This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: 3.1 preprocessor regression?


Zack Weinberg <zack@codesourcery.com> writes:
> On Thu, May 16, 2002 at 05:48:46PM -0700, J.T. Conklin wrote:
> > This code:
> > 
> >         #define anglequote(x) < ## x ## >
> >         #include anglequote(stdio.h)
> 
> Serious question: Why on earth would you do this?

As I said, it's not actually my code.  

I ran into it for the first time today in beta code provided by my
employer's RTOS vendor.  I'm trying to replace the vendor supplied
toolchain (which are based on older gcc, binutils, etc. releases),
with something more up to date.

The anglequote() macro was the minimal testcase for the behavior.
They're really doing something like:

        #define __CAT(x,y)      x ## y
        #define _CAT(x,y)       __CAT(x,y)

        #ifdef _INCLUDE_PREFIX
        #define _HDR(hdr)    < ## _CAT(_INCLUDE_PREFIX,hdr) ## >
        #else
        #define _HDR(hdr)    < ## hdr ## >
        #endif

        #ifdef _INCLUDE_PREFIX
        #define _CPU_HDR(hdr)   < ## _CAT(_INCLUDE_PREFIX,_CAT(_CPU, _CAT(/,hdr))) ## >
        #else
        #define _CPU_HDR(hdr)   < ## _CAT(_CPU,_CAT(/,hdr)) ## >
        #endif

The idea appears to be to be able to

        #include _CPU_HDR(foo.h)

instead of:
        #if defined __i386__
        #include <i386/foo.h>
        #elif defined(__mips__)
        #include <mips/foo.h>
        #elif defined(__powerpc__)
        #include <powerpc/foo.h>
        #elif ...
        #endif

> You can fix your code by removing the ## markers, they are and have
> always been unnecessary.

While I still have doubts whether the expansion of the anglequote
macro results in undefined behavior; while writing this reply I've
convinced myself that these more complicated macros do.  I'll take
that up with the OS vendor.

Many thanks,

        --jtc

-- 
J.T. Conklin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]