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
10 x 1036778084 = ??
I have just find strange answer, 10 x 1036778084 = 1777846248?? I'm using gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4 and gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4). These are same results, 10 x 1036778084 = 1777846248 C Lang: printf("%d \n", atoi("10367780849")); 1777846248 Result is 1777846257, and also following source, int y = 1036778084; int x = 10; int z; z = x * y; printf("%d x %d = %d\n", x,y,z); 10 x 1036778084 = 1777846248 -- View this message in context: http://gcc.1065356.n5.nabble.com/10-x-1036778084-tp1279231.html Sent from the gcc - bugs mailing list archive at Nabble.com.