Kenneth Bull <ke**********@gmail.comwrites:
On Apr 14, 4:00*pm, Ernie.Pasv...@cggveritas.com wrote:
>Is there a way to create a macro called *#redefine that will allow
redefinition without having to use #ifdef/#undef
For example, *I'd like to do something like this :
* * #define THING *"apple"
* * ... code
* * #redefine THING "banana"
* * ... code
* * #redefine THING "orange"
* * ... code
No, there isn't. A macro expansion cannot include preprocessor
directives.
just change the #redefine's to #define's
[...]
You don't need the #undef before reusing the #define.
Yes, you do. C99 6.10.3p2 says:
An identifier currently defined as an object-like macro shall not
be redefined by another #define preprocessing directive unless the
second definition is an object-like macro definition and the two
replacement lists are identical.
followed by similar wording for function-like macros.
I see this was cross-posted to comp.lang.c and comp.lang.c++. I
assume the rules for C++ are similar, but I'm not certain. It's
better to post to the newsgroup that covers the language you're
actually using.
--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"