Preprocessor; Clever #defines; not working

I know this isn't a great programming practice, but I have been messing around with the preprocessor in an attempt to become much more familiar with how it works and why it works. Basically I have created the following, and I would really appreciate it if someone could explain to me exactly why this isn't working.

1
2
3
4
5
6
7
#define RULE_NUMBER         1
#define IncrementRuleNumber #define LAST_NUMBER RULE_NUMBER   \
                            #undef  RULE_NUMBER               \
                            #define RULE_NUMBER LAST_NUMBER+1 \
                            #undef  LAST_NUMBER

IncrementRuleNumber


when I have this i get the following error

1
2
Line 14: error: stray ‘#’ in program
Line 14: error: 'define' does not name a type


Is there a way to accomplish what i was trying to do here?

Now for the following, I understand why it isn't working, but was wondering if anyone had some insight as to how to accomplish what I was going for.

1
2
#define test(message) #warning #message
test(ERROR IN YOUR PROGRAM!)


Thank you very much for your time and your help,
Brandon
Last edited on
In both cases the problem is that the preprocessor is not "recursive".

For your first example, you can look at the boost metaprogramming library (mpl) at www.boost.org.

For the second, there are possibly translations of your code (BOOST_STATIC_ASSERT); it depends on what you are trying to do.
That looks like it may be just what I was looking for actually. Also, that Boost.org site is amazing, I wish I would have came across it sooner.

Thank you very much,
Brandon
Topic archived. No new replies allowed.