开发者

Visual C++ 2010 solution-wide macros with parameters

开发者 https://www.devze.com 2023-01-01 10:15 出处:网络
I\'m trying to compile some source code with Visual C++ 2010 Express. The code was written for GCC, and contains attributes like this:

I'm trying to compile some source code with Visual C++ 2010 Express. The code was written for GCC, and contains attributes like this:

struct something {
...
} __attribute__((packed));

Since this is not standard C++ syntax, Visual C++ doesn't recognize it. With this macro prior to the struct declaration, it works fine:

#define __attribute__(p)

But I don't want to alter the files. I created a new property sheet (GccCompat), and went to Preprocessor Definitions, and added the macro, like this:

__attribute__(p)

or like this:

__attribute__(p)=

But it doesn't work. It's 开发者_运维技巧simply not called. If I define just __attribute__ (without parameters) in the same location, the macro is correctly defined. Note that the command line that is generated looks fine (the macros with parameters are passed exactly the same as the ones without), but the compiler seems to ignore it. So, how can I globally define my macro with a parameter?


It might be impossible, at least that way. Notice that Microsoft's documentation of the /D option doesn't specify a syntax for macros that take arguments.


Defining macros in the IDE is generally focused on the nature of creating a /D:CPP_TOKEN flag for the compiler, i.e. #define CPP_TOKEN.

In the advanced compiler settings you may be able to define such a macro as /D:"attributes(p)=/nothing/" or something like that. Just open the VS command prompt and see what it says. GCC 4.2 will allow something like that (using it's -D switch), but I don't have MSVC10 handy.

0

精彩评论

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