【发布时间】:2019-05-10 10:24:17
【问题描述】:
以下 const 在我正在测试 MISRA 准则违规的项目文件中声明为
__attribute__ ((section(".abc.dfe"))) const volatile uint8 attributeVariable = 0;
MISRA 测试产生以下消息
A compatible declaration shall be visible when an object or function with external linkage is defined.
Global definition of 'attributeVariable ' variable has no previous declaration.
我已经修复了其他未使用 __attribute__ 关键字的全局定义,将其声明为
extern const volatile uint8 attributeVariable;
在头文件中。我不确定是否可以在使用 __attribute__ 关键字时以相同的方式在标题中编写声明。 __attribute__ 会影响我编写变量外部声明的方式吗?
【问题讨论】:
-
你应该测试一下。当您的声明不包含该属性时会发生什么?
-
我会,但我担心我可能会改变函数的行为,因为我不是文件的作者——我的团队从以前的开发人员那里“继承”了它。我认为 MISRA 在这种情况下会产生警告消息,但我宁愿采取更谨慎的方式,咨询对代码中到底发生了什么有更深入了解的人。