【发布时间】:2011-11-17 03:56:00
【问题描述】:
我正在尝试编写类似于以下内容的宏:
#ifndef DEPRECATED_ATTRIBUTE_MESSAGE
#define DEPRECATED_ATTRIBUTE_MESSAGE(message) __attribute__((deprecated (message)))
#endif
这有效,但仅适用于 Apple LLVM 3.0 编译器。它在编译时因其他任何事情而中断,这意味着我必须将其剥离到
#ifndef DEPRECATED_ATTRIBUTE_MESSAGE
#define DEPRECATED_ATTRIBUTE_MESSAGE(message) __attribute__((deprecated))
#endif
用处不大。
我的问题:
我认为解决方案是在编译时应用一些宏来识别编译器的版本。有没有办法区分 Apple LLVM 3.0 编译器与 LLVM GCC 4.2 或 GCC 4.2(或其他)?
理想情况下,我想解决这样的问题,但我找不到合适的宏来解决它:
#ifdef [Apple LLVM 3.0]
#ifndef DEPRECATED_ATTRIBUTE_MESSAGE
#define DEPRECATED_ATTRIBUTE_MESSAGE(message) __attribute__((deprecated (message)))
#endif
#else
#ifndef DEPRECATED_ATTRIBUTE_MESSAGE
#define DEPRECATED_ATTRIBUTE_MESSAGE(message) __attribute__((deprecated))
#endif
#endif
【问题讨论】:
标签: gcc xcode4 macros llvm conditional-compilation