This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: 10 x 1036778084 = ??


On 07/07/2016 10:07 PM, Nobby-Hirand wrote:
I have just find strange answer, 10 x 1036778084 = 1777846248??

Your target has 32-bit integers. The value 1036778084 is close to the largest representable value. Multiplying by anything larger than 2 causes an overflow, and the result gets truncated. Try using %x to print hex values to see what is wrong. Or use long long instead of int to get 64-bit values.

FYI With a more recent gcc version, you can compile with -fsanitize=undefined and get this:

weathertop:2044$ ./a.out
tmp.c:11:5: runtime error: signed integer overflow: 10 * 1036778084 cannot be represented in type 'int'

FYI gcc-bugs@gcc.gnu.org is used for output from our bugzilla database. You shouldn't send email to this address. You should either send email to gcc-help or file a bug at https://gcc.gnu.org/bugzilla/

Jim


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]