Lia*_*con 5 c attributes gcc c99 visual-c++
我想知道__attribute__在使用 MSVC 时处理包含 GCC扩展名的代码的最佳方法是什么。以下是处理此问题的安全方法:
#define __attribute__(x) /* blank - should simply ignore thanks to C preprocessor */
Run Code Online (Sandbox Code Playgroud)
谢谢!
__attribute__不是宏,它是 GCC 特定的扩展,需要用适当的等效 Visual C++ 替换。它的等价物通常是__declspec:
http://msdn.microsoft.com/en-US/library/dabb5z75(v=vs.110).aspx
例如:
#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
Run Code Online (Sandbox Code Playgroud)