有了 GCC,我可以这样做:
typedef struct {
char a;
int n;
} MyStruct;
MyStruct ms __attribute__((section("MySection"))) = {'x', 33};
MyStruct *pms = &ms;
Run Code Online (Sandbox Code Playgroud)
但是,当我按如下方式使用复合文字时,GCC 会发出警告: 'section' 属性不适用于类型 [-Wattributes]。
typedef struct {
char a;
int n;
} MyStruct;
MyStruct *pms = &(MyStruct __attribute__((section("MySection")))){'x', 33};
Run Code Online (Sandbox Code Playgroud)
有什么办法可以过去吗?谢谢。
MISRA-C:2004规则10.1不允许隐式扩展函数参数或返回表达式的类型,如以下代码片段所示:
void foo1(int16_t x);
int16_t foo2(void)
{
int8_t s8a;
...
foo1(s8a); /* not compliant */
...
return s8a; /* not compliant */
}
Run Code Online (Sandbox Code Playgroud)
但是,根据我的理解,它们与分配情况没有什么不同:
s16a = s8a; /* compliant */
Run Code Online (Sandbox Code Playgroud)
重点是什么?谢谢.