mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   Programming (https://www.mersenneforum.org/forumdisplay.php?f=29)
-   -   More Weirdness (https://www.mersenneforum.org/showthread.php?t=11868)

R.D. Silverman 2009-05-14 19:31

More Weirdness
 
It's heavy mystery time. Under Linux gcc I have:


#define T 15
#define K 32

printf("%d %d %d %d\n", T, K, T*K, (T)*(K) );


yields

15 32 108 480

!!!!!!!

What is the preprocessor doing??? Why is it misinterpreting T*K?
and furthermore..... how is it misinterpreting it??????

jrk 2009-05-14 19:44

I get: 15 32 480 480

Which version of GCC?

gcc version 4.3.2 20081105 (Red Hat 4.3.2-7) (GCC)

edit: also tried gcc version 3.4.6 20060404 (Red Hat 3.4.6-9) and it still works.

ldesnogu 2009-05-24 18:11

[quote=R.D. Silverman;173557]What is the preprocessor doing??? Why is it misinterpreting T*K?
and furthermore..... how is it misinterpreting it??????[/quote]
If you think your preprocessor is playing tricks on you, you can try gcc -E, which will produce a file after preprocessing has been done.

grandpascorpion 2009-05-24 21:44

Why not use const int rather than define?

CRGreathouse 2009-05-24 22:01

[QUOTE=grandpascorpion;174700]Why not use const int rather than define?[/QUOTE]

I imagine he's more interested in giving us a minimal example displaying the (bug? weirdness?) he's found than anything else.


All times are UTC. The time now is 21:58.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.