4

使用 GCC,我可以这样做:

typedef struct {
    char a;
    int n;
} MyStruct;

MyStruct ms __attribute__((section("MySection"))) = {'x', 33};
MyStruct *pms = &ms;

但是当我如下使用复合文字时,GCC 会抱怨警告:'section' 属性不适用于类型 [-Wattributes]

typedef struct {
    char a;
    int n;
} MyStruct;

MyStruct *pms = &(MyStruct __attribute__((section("MySection")))){'x', 33};

有什么办法过得去吗?谢谢你。

4

0 回答 0