user2280250
user2280250

Reputation: 41

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?

Upvotes: 0

Views: 153

Answers (3)

Walt
Walt

Reputation: 332

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.

Upvotes: 0

Jens Gustedt
Jens Gustedt

Reputation: 78943

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.

Upvotes: 0

Gabe
Gabe

Reputation: 86768

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> 

Upvotes: 1

Related Questions