Preprocessor behavior
Zack Weinberg
zackw@stanford.edu
Mon Oct 16 13:42:00 GMT 2000
On Mon, Oct 16, 2000 at 01:26:31PM -0700, 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>".
MSVC is buggy, gcc's behavior is correct. The tokens on either side
of a ## are not to be macro-expanded before pasting - C99 6.10.3.3
paragraph 2.
You can get the behavior you wanted with an extra macro layer:
#define WIDESTR(x) WIDESTR_(x)
#define WIDESTR_(x) L##x
#define WIDEFILE WIDESTR(__FILE__)
which should still work with MSVC.
zw
More information about the Gcc
mailing list