• Advertisement

Archived

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

#ifdef 1

This topic is 5308 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

Hi! I have seen some code similar to this in other ppls code #ifdef 1 do something #else do something else what does it mean.. isnt 1 always true /Erik

Share this post


Link to post
Share on other sites
Advertisement
no "while(1)" tests 1 against itself and will always be true...
but "#ifdef 1" means means if 1 has been defined do the bext code. for the code ofter "#ifdef 1" to work a statement that defines 1 must be included such as "#define 1" this is ithink normaly used for debuging perposes. for example

#define debug
#ifdef debug
//debug code
#else
//other code

hope that helps
Ps sorry about the spelling mistakes im drunk


[edited by - vermillion on October 7, 2003 5:36:07 PM]

[edited by - vermillion on October 7, 2003 5:37:54 PM]

Share this post


Link to post
Share on other sites
I''ve seen the following code used to comment out code. example:

#if 0
// platform specific code that is meant to be commented out
// on another platform
#endif
// non platform specific code

But, if you meant to put ifdef then vermillion should be correct (not totally sure on that though, but I think #define''s can start with numbers).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by brassfish89
I''ve seen the following code used to comment out code. example:

#if 0
// platform specific code that is meant to be commented out
// on another platform
#endif

Are you sure it''s not like
#ifdef LINUX
or
#ifdef WIN32
? I doubt anyone would but platform-specific code like you said, so that it has to be manually changed in all the places where such code exists.

Share this post


Link to post
Share on other sites
Thanks 4 the answers. It was #if 0, i remembered it wrong.
Then I guess its like brassfish89 says. It make sense.

thnx for the answers!

Share this post


Link to post
Share on other sites
It's probably more often used in deprecating code, I often do

#if 0
// old code
#else
// new code
#endif

and then can toggle between them by switching the 0 to a 1 as the testing process goes on. It's just a more convenient way than commenting out chunks.

As it becomes stable sometimes the old code is deleted, but probably more often is left as cruft



[edited by - JuNC on October 7, 2003 6:26:38 PM]

Share this post


Link to post
Share on other sites

  • Advertisement