Skip to main content
gamedev.net
🔒 Locked

using #defined values

Started by oveja-carnivora Jun 1, 2002 at 11:44 PM 20 replies 1k views
Original Post
oveja-carnivora
oveja-carnivora
can anybody tell me why I cant divide by a #defined value? ex- This C++ syntax doesnt work: #define X 5 long Y = 3; long Z = Y/X; but this does: #define X 5 long Y = 3; long Z = Y/(X+0); Thanks, Ben
Null and Void
Null and Void
That are both valid examples. What do you mean by "doesn''t work"?

oveja-carnivora
oveja-carnivora
I mean that it gives me a syntax error on the character after the #defined value, my actualy code is:

#define LoadStepNum
...
long LoadBarProgress = 0;
...
LoadBarProgress += screenwidth / (LoadStepNum + 0);

without the () and the + 0 it gives me a syntax error on the '';''

this doesnt make any sense, so thanks for the help

-Ben
Melraidin
Melraidin
Only thing I notice is that you don''t have anything defined for LoadStepNum. Make sure there''s a number in there, and make sure that you''ve got it written as:

#define LoadStepNum 7

No equal sign or anything...

Although I''m betting you''ve already got it like this and it was simply a copying error.
oveja-carnivora
oveja-carnivora
wow do I feel stupid, I was sure I typed a 4 there.
ack

I think I will go hide until this message is forgotten.
Xai
Xai
bump
elis-cool
elis-cool
lol... bump
Well I have done similer things... note similer, but in no way was it near this stupid!!

CEO Plunder Studios
[email=esheppard@gmail.com]esheppard@gmail.com[/email]
oveja-carnivora
oveja-carnivora
I wasnt getting any, just the syntax errors. not very intelegent error message, but not a very intelegent thing to be doing so oh well

quote:
Original post by ZealousElixir
Heh. How did you not notice the "divide-by-zero" errors you were getting?



[edited by - oveja-carnivora on June 2, 2002 3:14:27 PM]
zealouselixir
zealouselixir
LoadBarProgress += screenwidth / (LoadStepNum + 0);

Without LoadStepNum defined, that would appear to the compiler as

LoadBarProgress += screenwidth / (+ 0);

and furthermore

LoadBarProgress += screenwidth / 0;

So, if you ran that code, how did you avoid a process-fatal error?

Later,
ZE.


//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]
[twitter]warrenm[/twitter]
oveja-carnivora
oveja-carnivora
That actualy never ran, it was a one of a bunch of errors that I was working thru. just trying to fix compiler errors
JonStelly
JonStelly
Well done fellas, very classy. Would you also like to mug my grandmother while you''re kicking this guy for having the nerve to make a mistake?
zealouselixir
zealouselixir
"It takes a big man to cry, but it takes a bigger man to laugh at that man."

Classy it weren''t, but boys will be boys. I doubt seriously that your repremand, no matter how appropriate, will have the intended effect. Besides, he took our time, we take his pride. It would be fair enough to stop there, but we also gave him the ability to recognize stupid errors in the future.

No harm intended.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]
[twitter]warrenm[/twitter]
Jason2Jason
Jason2Jason
would using a const long instead of a #define be better? I''m prob wrong so ignor me if I am. Its just i read somewhere that its ment to be ''better practice'' to use const''s and not #define''s in C++. I still don''t completely follow that tho.

-J
zealouselixir
zealouselixir
Macros are evil for three reasons. See the C++ FAQ Lite for more info. For single values, const variables are more desirable, but they require you do use extern and to define the const in a single translation unit, whereas #define can be simply tossed into a

Wait a minute. const values DON'T require you to use extern, do they?

Never mind.

Anyway, macros are evil, and yes, in this situation, it would have been better to use const (certainly would have eliminated the need for this thread... )

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]
EDITED for schtuff.


[edited by - zealouselixir on June 2, 2002 7:48:53 PM]
[twitter]warrenm[/twitter]
Beer Hunter
Beer Hunter
Macros are only evil when used to replace inline functions, constants or typedefs
zealouselixir
zealouselixir
My project is frying my brain...I didn''t get that for 5 seconds...
[twitter]warrenm[/twitter]
Xai
Xai
Just imagine if he hadn''t put the smiley face!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.