• Advertisement

Archived

This topic is now archived and is closed to further replies.

using #defined values

This topic is 5739 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
how stupid can you be...
I''ll bet you''ll be the best error programmer world wide
lol

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
"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.]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
True 'nuff. The _only_ things I use macros for are:

- Debug code (stuff guaranteed to be ignored during compilation when I turn off debug flags)
- The afore-mentioned debug flags
- Code requiring macros to be compatible with other code. Example: DirectX 8's implementation of DirectInput requires you to define a version number macro to avoid getting stupid distracting warning messages. Bollocks.

[edit]Whoops, not a UBB bulletin board--bad tags. [/edit]

---
blahpers

[edited by - blahpers on June 3, 2002 12:45:23 AM]

Share this post


Link to post
Share on other sites

  • Advertisement