Preprocessor behavior

Dave Brolley brolley@redhat.com
Mon Oct 16 13:34:00 GMT 2000


Munagala Ramanath wrote:
> 
> Hi,
> 
> Using the macro:
> #define T( X ) L ## X
> to create a wide string fails with the predefined __FILE__ symbol
> (i.e. T(__FILE__)) with gcc-2.95.2 on Sparc/Solaris7 because it
> apparently catenates the body to get L__FILE__ before rescanning.
> 
> MSVC yields the expected L"<filename>".
> 
> Is this a bug in gcc or is it required by the standard ? Does anybody
> know any way to generate wide string literals out of __FILE__ ? Thanks.

gcc is correct. The tokens get concatenated with out the argument
being expanded. In order to produce the result you want, you need
to use a two stage expansion:

#define T ( X ) L ## X
#define ET ( X ) T ( X )
ET (__FILE__)

The argument (__FILE__ gets expanded in ET and then passed on to
T in this case.

Dave


More information about the Gcc mailing list