开发者

Problem with Microsoft Compiler macro expansion spaces

I have this problem in a header macro expansion under Microsoft C Compiler Preprocessor:

custom.h

.
.

# define _OTHER_INCLUDE_DIR C:\3rdparty\usr\include

# define _3RD_PARTY_HEADERS(headername) <_OTHER_INCLUDE_DIR\headername>
.
.

With a header test:

headertest.h

.
.

#include _3RD_PARTY_HEADERS(stdint.h)
.
开发者_开发百科

Microsoft C preprocessor expand second line like(custom.h):

#include  <C:\3rdparty\usr\include\headername>

If I set :

# define _3RD_PARTY_HEADERS(headername) <_OTHER_INCLUDE_DIR\ headername>

The result is:

#include  <C:\3rdparty\usr\include\ stdint.h>

How I can fix that?


It looks like you want to juxtapose your directory and your header name. You use ##, like this:

# define _3RD_PARTY_HEADERS(headername) <_OTHER_INCLUDE_DIR\\##headername> 


Is there no way to have the \ character sequences to be represented differently? The problem is that this is an escape character for C and C++. C99 explicitly states

If the characters ', \, ", //, or /* occur in the sequence between the < and > delimiters, the behavior is undefined.

(There is a similar phrase for "..." includes.)

and I imagine that for C++ there must be something similar. So maybe you just could use / and the compiler would replace them internally to refer to the correct file on your system.


You know, most compilers have a command-line argument to add to the include path... -I or /I most likely for the Microsoft one. One doesn't usually do what you're doing here, never mind whether or not you can make it work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜