Re: Macro redefinition



Tor Rustad <tor_rustad@xxxxxxxxxxx> writes:
Dave Hansen wrote:

<snip>

My question is simply, is the above C code allowed?
It's a pretty common idiom in the code I work with. One caveat:
don't
forget to #undef EXPAND_DEF before redefining it.

Is really the #undef needed in this case? This is a function-like
macro, and the re-definition had identical argument list.

C99 6.10.3p2:

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. Likewise, an identifier currently
defined as a function-like macro shall not be redefined by another
#define preprocessing directive unless the second definition is a
function-like macro definition that has the same number and
spelling of parameters, and the two replacement lists are
identical.

This is a constraint.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • Re: Macro redefinition
    ... forget to #undef EXPAND_DEF before redefining it. ... An identifier currently defined as an object-like macro shall not ... two replacement lists are identical. ...
    (comp.lang.c)
  • Re: More static type fun.
    ... > BAZ ... It certainly looks like you successfully redefined BAZ as a macro. ... So how about redefining functions? ... likely requires recompilation, and redefinition from a function to another ...
    (comp.lang.lisp)
  • Re: How to generate random numbers in C
    ... make that modification due to file access permissions. ... redefining the macro in user code. ... int main ... In fact, since redefining RAND_MAX invokes ...
    (comp.lang.c)
  • Re: Macro redefinition
    ... An identifier currently defined as an object-like macro shall not ... second definition is an object-like macro definition and the two ... replacement lists are identical. ...
    (comp.lang.c)
  • Re: Why R6RS is controversial
    ... he wanted to bind an identifier like "this.speed" ... to an identifier macro that would generate a reference ... ordinary macro. ... special form expects a named location ...
    (comp.lang.scheme)