I didn't use an int. take a look.
an int shouldn't even BE IN there. if anything, one should think you convert
to
the compiler should know to convert everything at least to the return or
assign type I should think. the data type should not be hard to detect
by the parser.
I hope someone makes that a feature someday.
for instance,
int = short*char*short; //I think should be compiled as int=int*int*int; return
short*char*short; //that returns an int should be compiled as return
int*int*int;
this is what I mean. as simple as that. I should have given examples.
*If* I am assigning an int but the calculations require an int64_t
temporarily (which is what I think you are describing), then I already
know I need to do the conversions myself manually:
int=static_cast<int64_t>(char)*static_cast<int64_t>(short)*static_cast<int64_t>(int);
but where that int is coming from, I have no clue. I hope it's not in the
standard, because it's messing me up. maybe it's a compiler bug.
If this *is* a compiler bug, I would like to see it fixed. if this is an
oversight in the c and c++ language standard, I would like to see *that*
fixed. I don't think a change like that would do any harm. I think it would
improve code reliability. people assume a lot of things that aren't true when
they say in Engineering school "all smaller number data types are upconverted
to larger number data types". it's not true in all instances. I would like to
see a professor put this out as a programming example or someone put this out
in a "how not to program in c++" book.
>________________________________
> From: Martin Mitáš <[email protected]>
>To: [email protected]
>Sent: Thursday, March 15, 2012 12:57 AM
>Subject: Re: [Mingw-w64-public] bug: conversion of integers and other numbers
>not there
>
>
>
>It works correctly, because sizeof(int) == 4 and 125000000000
>is too big for 32 bits. If you take the least significant four
bytes
>of that value, you get (what a surprise) exactly 445948416.
>
>The three vars are expanded from short to int and multiplicated
>(still into an int), then the result is expanded to uint64_t by the
>assignement, but it is already too late.
>
>Use this instead:
>uint64_t n = (uint64_t) cyl * head * sector;
>
>Regards,
>Mity
>
>
>Dne 15.3.2012 0:15, Jim Michaels napsal(a):
>bug: conversion of integers and other numbers not there.
>>#include <iostream>
>>#include <tr1/stdint.h>
>>using namespace std;
>>int main(void) {
>> unsigned short cyl=5000, head=5000, sector=5000;
>> uint64_t n=cyl * head * sector; //result should be
>> cout<<"result should be
125000000000:="<<n<<endl;
>> return 0;
>>}
>>/*
>>Wed 03/14/2012
16:10:39.73|C:\prj\test\mingw-w64\conversion|>c
>>result should be 125000000000:=445948416
>>
>>Wed 03/14/2012
16:10:46.90|C:\prj\test\mingw-w64\conversion|>
>>*/
>>
>>remember in engineering school they told us the compiler
will convert all shorts to ints, etc, yada yada?
>>well, this doesn't work in gcc.
>>I have tried this both with mingw, mingw-w64, and djgpp.
>>you can try this with 20111127 auto build if you like.
>>
>>
>>
>>-------------
>>Jim Michaels
>>[email protected]
>>[email protected]
>>http://JimsComputerRepairandWebDesign.com
>>http://JesusnJim.com (my
personal site, has software)
>>---
>>Computer memory measurements, SSD measurements, microsoft disk
size measurements (note: they will say GB or MB or KB or TB
when it is not!):
>>[KiB] [MiB] [GiB] [TiB]
>>[2^10B=1,024B=1KiB]
>>[2^20B=1,048,576B=1MiB]
>>[2^30B=1,073,741,824B=1GiB]
>>[2^40B=1,099,511,627,776B=1TiB]
>>hard disk industry disk size measurements:
>>[KB] [MB] [GB] [TB]
>>[10^3B=1,000B=1KB]
>>[10^6B=1,000,000B=1MB]
>>[10^9B=1,000,000,000B=1GB]
>>[10^12B=1,000,000,000,000B=1TB]
>>
>>
>>
>>
>>
>>------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
>>
>>
>>_______________________________________________
Mingw-w64-public mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>------------------------------------------------------------------------------
>This SF email is sponsosred by:
>Try Windows Azure free for 90 days Click Here
>http://p.sf.net/sfu/sfd2d-msazure
>_______________________________________________
>Mingw-w64-public mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>
>
>------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public