views:

209

answers:

2

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?

+1  A: 

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.

unwind
Since you wrote "at least that way", I'd also accept other ways :) I just don't want to change the original code, if not necessary. I will do by adding conditional compilation for the packing if I don't find a better solution, though.
OregonGhost
+1  A: 

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.

TerryP
Note that adding a macro with parameters to the property sheet *will* generate `/D "__attribute__(p)"` as command line. It just doesn't work. However, "advanced" seems to be a good point: In Advanced C++ options, there's a forced include file option. I created a small file just with the required definition and added it as forced include, and it works. Now, for some strange reason, I found occurences of `__attribute` (without the trailing underscores)...
OregonGhost