Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dealing with __attribute__ in MSVC

I was wondering what the best way to deal with code containing GCC's __attribute__ extension when using MSVC. Is the following a safe way of dealing with this:

#define __attribute__(x) /* blank - should simply ignore thanks to C preprocessor */

Thanks!

like image 621
Liam Deacon Avatar asked Feb 09 '15 13:02

Liam Deacon


1 Answers

__attribute__ is not a macro, it is a GCC specific extension that needs to be replaced with appropriate equivalent Visual C++ has. Its equivalent is usually __declspec:

http://msdn.microsoft.com/en-US/library/dabb5z75(v=vs.110).aspx

For example:

#if defined(_MSC_VER)
#define DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax.
#else
#if defined(__GNUC__)
#define DLL_PUBLIC __attribute__ ((dllexport))
#endif
like image 51
Kornel Avatar answered Nov 12 '22 21:11

Kornel