• Advertisement

Archived

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

I saw this in a book, now why doesn't it work?

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

Alright, I saw something like the following in a LaMothe book, but I can''t get it to work: ---------------------- #define STAGE1 #define STAGE2 int stage = 0; int main() { switch(stage) { case STAGE1: // do stuff for stage 1 case STAGE2: // do stuff for stage 2 case default: // do default stuff } return 0; } ---------------------------- I write something like this (of course the comments are placeholders for real commands), and I get an error for mismatched types or something. Now why would that happen? The preprocessor should just use text replacements when assigning a #defined variable to an int, etc., as I''ve read many times before. So why doesn''t this work. I always have to rewrite the code with an enumerated constant or something to make up for it. What''s wrong with the code?

Share this post


Link to post
Share on other sites
Advertisement
What is STAGE1 defined as? Maybe if you did

#define STAGE1 1
#define STAGE2 2

The preprocessor wont replace STAGE1 with anything because STAGE1 isn''t defined as being anything. With the above, STAGE1 is defined as being 1, which the preprocessor will insert as a literal.

------------
- outRider -

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
im not gonna repeat dat..

(always anonymous)

Share this post


Link to post
Share on other sites

  • Advertisement