【发布时间】:2011-10-28 04:35:13
【问题描述】:
我正在努力完善一些现有的 C 代码,以便将其移植到新的编译器(嵌入式软件,我们正在切换硬件)。所以我试图用 lint 清理当前代码,但我被 lint 认定为强类型违规的分配难住了。
我得到的错误:
--- Module: GenericFileName.c
GenericFileName.c ... Warning 632: Assignment to strong type
(SubStructureType_T) in context: assignment
它所引用的代码行(为便于阅读而更改了名称):
void foo(void)
{
extern const StructureType_T parent;
const SubStructureType_T *localChild;
localChild = parent.child; //<-- lint complains about this assignment
...
}
StructureType_T的相关部分:
typedef struct
{
const struct SubStructureType_T *child;
...
}StructureType_T;
最后,启用强类型检查的 lint 选项:
-strong(AcXJcb)
任何见解将不胜感激。我已经四处寻找帮助,但没有找到太多。我猜 lint 是一个相当古老的工具。感谢阅读!
【问题讨论】:
-
parent实际上(全局)在哪里以及如何定义您已要求外部链接的? -
糟糕,非常好的问题。我应该把它包括在内。它看起来像这样:'const StructureType_T parent = { 0,0,0,...,0}'。它存在于另一个模块中。
-
const StructureType_T parent = { 0,0,0,...,0}; -
这没什么用。既然您说它是一个旧工具,请尝试在指针的初始化列表中设置为 NULL 而不是 0。
-
这有关系吗?我在
#pragma tsection .parent声明之后得到了定义。由于应用程序的重要性质,我们使用这种类型的东西来非常谨慎地确定某些地址的存储位置。
标签: c lint strong-typing