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

Started by
1 comment, last by Some Guy 22 years, 5 months ago
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?
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 -
im not gonna repeat dat..

(always anonymous)

This topic is closed to new replies.

Advertisement