R
Richard Meister
Hi,
I'd like to define several constants and make sure that all of them are
smaller than a given other constant. I thought this could be done by a
simple macro. Something like this:
#define MAX 999
#define DEF_CHECKED_VAL( name, value) #if (value < MAX) \
#define name MAX \
#else \
#define name value \
#endif
So
DEF_CHECKED_VAL(test_1, 33) should expand to #define test_1 33
and
DEF_CHECKED_VAL(test_2, 1000) should yield #define test_2 999
As you probably know (and I learned today) this doesn't work. The most
relevant FAQ to this problems seems to be "10.25 I've got this tricky
preprocessing I want to do and I can't figure out a way to do it."
Unfortunately writing my own preprocessor isn't really an option and I
can't believe that I'm the first one who'd like to implement this
functionality. Is there a well-known solution to my problem, or am I doing
something fundamentally stupid?
Thanks for any help, Rick
I'd like to define several constants and make sure that all of them are
smaller than a given other constant. I thought this could be done by a
simple macro. Something like this:
#define MAX 999
#define DEF_CHECKED_VAL( name, value) #if (value < MAX) \
#define name MAX \
#else \
#define name value \
#endif
So
DEF_CHECKED_VAL(test_1, 33) should expand to #define test_1 33
and
DEF_CHECKED_VAL(test_2, 1000) should yield #define test_2 999
As you probably know (and I learned today) this doesn't work. The most
relevant FAQ to this problems seems to be "10.25 I've got this tricky
preprocessing I want to do and I can't figure out a way to do it."
Unfortunately writing my own preprocessor isn't really an option and I
can't believe that I'm the first one who'd like to implement this
functionality. Is there a well-known solution to my problem, or am I doing
something fundamentally stupid?
Thanks for any help, Rick