Compile error: function name collisions between port.h and math.h?

James Dennett jdennett at acm.org
Thu Apr 5 01:54:25 PDT 2007


Anders F Björklund wrote:
> If the code including "port.h" actually uses those,
> it's possible to store them away and restore later:
> 
> #define OLD_foo    foo

This doesn't remember the definition of foo; it just
makes OLD_foo expand to the token "foo".  (As macro
replacement is somewhat recursive, that would then
be expanded if a macro called foo was defined in the
relevant context of use.)

> #undef foo

So here, OLD_foo just expands to foo.

> ...
> #define foo OLD_foo

And now there's a loop, but the C preprocessor rules
stop the infinite recursion, so foo is defined as a
macro which ultimately expands to foo, and OLD_foo
expands to OLD_foo, in effect just as if you had
done

#define foo foo
#define OLD_foo OLD_foo

Sorry; the C preprocessor really doesn't give any
nice to way handling scoping of definitions.

-- James


More information about the D.gnu mailing list