把c / c ++ __attribute __关键字放在哪里

时间:2018-02-15 17:24:25

标签: c gcc

通常__attribute__放在声明之后,但是如何使用typedef。

typedef struct {} PKD_1 __attribute__ ((packed));
typedef struct {} __attribute__ ((packed)) PKD_2;
typedef struct {} DPCT_1 __attribute__ ((deprecated));
typedef struct {} DPCT_2 __attribute__ ((deprecated));
typedef struct {} __attribute__ ((deprecated)) DPCT_3;

DPCT_2 dpct_2;

我尝试使用clang编译此代码,并收到类似警告:

cpp/main.cpp:1:41: warning: 'packed' attribute ignored [-Wignored-attributes]
typedef struct {} PKD_1 __attribute__ ((packed));
                                        ^
cpp/main.cpp:5:9: warning: '' is deprecated [-Wdeprecated-declarations]
typedef struct {} __attribute__ ((deprecated)) DPCT_3;
        ^
cpp/main.cpp:5:9: note: '' has been explicitly marked deprecated here
cpp/main.cpp:7:1: warning: 'DPCT_2' is deprecated [-Wdeprecated-declarations]
DPCT_2 dpct_2;
^
cpp/main.cpp:4:19: note: 'DPCT_2' has been explicitly marked deprecated here
typedef struct {} DPCT_2 __attribute__ ((deprecated));
                  ^
3 warnings generated.

所以,
1.为什么在typedef名称之前需要__attribute__ ((packed))? (PKG_1警告。)
2.为什么我将__attribute__ ((deprecated))放在typedef名称之后,它只在我定义struct varible时报告不推荐使用,但是当它放在名称DCPT_3之前时,它会在typedef语句时立即报告警告

0 个答案:

没有答案