GCC的__attribute__不适用于LLVM中的struct成员

时间:2014-09-26 12:44:13

标签: c struct attributes llvm llvm-clang

使用GCC' __attribute__时,我注意到在结构中使用属性时会被忽略。

struct MyFCNPointers {
    void (*MyFCNPointer)(const char *str, ...) __attribute__((__format__(printf, 1, 2)));
};

struct MyFCNPointers MyFCNPointers;

// Gives no warning at all
MyFCNPointers.MyFCNPointer("Hello %s");

然而,这有效:

void (*MyFCNPointer)(const char *str, ...) __attribute__((__format__(printf, 1, 2)));

// Gives the expected warning
MyFCNPointer("Hello %s");

这有什么理由吗?更重要的是有一个解决方法吗? (我使用结构来为函数提供命名空间。例如:X.Thread.Mutex__alloc()

修改

gcc -v给出了

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix

0 个答案:

没有答案
相关问题