c - How do I force 64 bit integer arithmetic on OS X? -
I'm trying to force a 64-bit full integer on OS X 10.5.6. An Apple MacBook is running on Intel Core 2 Duo Here's my C code:
Include # lt; Stdio.h & gt; Int main () {long A = 2147483647; / * == 2 ^ 32 - 1 * / tall Epulus 1; Printf ("a ==% d size (a) ==% d \ n", one, size (a)); Aplus1 = a + 1; Printf ("aplus1 =% d \ n", aplus1); } Compiling without any switches produces the following:
$ gcc testlong.c -o testlong; ./ testlong a == 2147483647. sizeof (A) == 4 aplus1 = -2147483648 Compiling with switch yield:
$ gcc Testlong.c -o testlong-m64; ./testlong a == 2147483647. sizeof (a) == 8 aplus1 = -2147483648 Then the second version is using 64 bit storage, but still produces overflow error , Although 2 ^ 32 should be fine within a 64 bit integer range. Any ideas?
I would prefer a solution that can be forced from a GCC option, instead I need to change the many lines of source code (my actual problem is not particularly the example above, but rather I need to emphasize the long integer arithmetic in the more general condition).
Not only do you have to use long hours, but you should also change the printf () statement accordingly.
Add # & lt; Stdio.h & gt; Int main () {Long time a = 2147483647; / * == 2 ^ 32 - 1 * / long aplus1; Printf ("a ==% lld. Sizeof (a) ==% d \ n", a, sizeof (a)); Aplus1 = a + 1; Printf ("aplus1 =% lld \ n", aplus1); } % lld is the longest code.
Clearly 64-bit programs can use% d for 64-bit integers - I do not know to configure it to be compiled in this mode it is possible.
Comments
Post a Comment