小编din*_*rie的帖子

我可以为复合文字指定节属性吗?

有了 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)

有什么办法可以过去吗?谢谢。

attributes gcc compound-literals

5
推荐指数
0
解决办法
224
查看次数

为什么MISRA-C在某些情况下不允许隐式扩大类型?

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)

重点是什么?谢谢.

c type-conversion misra

5
推荐指数
1
解决办法
149
查看次数

标签 统计

attributes ×1

c ×1

compound-literals ×1

gcc ×1

misra ×1

type-conversion ×1