gpt4 book ai didi

c - 在 MSVC 中处理 __attribute__

转载 作者:太空宇宙 更新时间:2023-11-04 02:00:04 24 4
gpt4 key购买 nike

我想知道在使用 MSVC 时处理包含 GCC 的 __attribute__ 扩展的代码的最佳方法是什么。以下是处理此问题的安全方法吗:

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

谢谢!

最佳答案

__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

关于c - 在 MSVC 中处理 __attribute__,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28411283/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com