mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Programming

Reply
 
Thread Tools
Old 2009-05-14, 19:31   #1
R.D. Silverman
 
R.D. Silverman's Avatar
 
Nov 2003

22×5×373 Posts
Default 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??????
R.D. Silverman is offline   Reply With Quote
Old 2009-05-14, 19:44   #2
jrk
 
jrk's Avatar
 
May 2008

109510 Posts
Default

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.

Last fiddled with by jrk on 2009-05-14 at 19:47
jrk is offline   Reply With Quote
Old 2009-05-24, 18:11   #3
ldesnogu
 
ldesnogu's Avatar
 
Jan 2008
France

10000111012 Posts
Default

Quote:
Originally Posted by R.D. Silverman View Post
What is the preprocessor doing??? Why is it misinterpreting T*K?
and furthermore..... how is it misinterpreting it??????
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.
ldesnogu is offline   Reply With Quote
Old 2009-05-24, 21:44   #4
grandpascorpion
 
grandpascorpion's Avatar
 
Jan 2005
Transdniestr

50310 Posts
Default

Why not use const int rather than define?
grandpascorpion is offline   Reply With Quote
Old 2009-05-24, 22:01   #5
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,987 Posts
Default

Quote:
Originally Posted by grandpascorpion View Post
Why not use const int rather than define?
I imagine he's more interested in giving us a minimal example displaying the (bug? weirdness?) he's found than anything else.
CRGreathouse is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
AVX2 weirdness bsquared Programming 1 2016-01-17 17:26
Achievement? No, just weirdness R.D. Silverman Lounge 5 2015-05-14 22:27
Linux weirdness; Help? R.D. Silverman Programming 3 2009-04-29 12:35
Benchmark Weirdness R.D. Silverman Hardware 2 2007-07-25 12:16
Official Windows Whines and Weirdness Thread rbarreira Lounge 11 2005-09-01 06:04

All times are UTC. The time now is 08:31.

Sat Jan 16 08:31:36 UTC 2021 up 44 days, 4:42, 0 users, load averages: 2.30, 2.09, 1.89

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

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.