$ cppcheck iotask/*.cc
Checking iotask/ioControl.cc ...
Checking iotask/ioControl.cc: TOOL_NML...
1/2 files checked 45% done
Checking iotask/ioControl_v2.cc ...
Checking iotask/ioControl_v2.cc: TOOL_NML...
2/2 files checked 100% done
iotask/ioControl.cc:90:1: error: The one definition rule is violated, different classes/structs have the same name 'iocontrol_str' [ctuOneDefinitionRuleViolation]
struct iocontrol_str {
^
iotask/ioControl_v2.cc:140:1: note: The one definition rule is violated, different classes/structs have the same name 'iocontrol_str'
struct iocontrol_str {
^
iotask/ioControl.cc:90:1: note: The one definition rule is violated, different classes/structs have the same name 'iocontrol_str'
struct iocontrol_str {
然后我查看了这些(大)结构定义,将它们导出到文件 a 和 b 中,经过一些格式化后发现 v2 的唯一区别确实只是之前的扩展:
Cppcheck 在 emc/iotask 中发出了一些声音,我倾向于同意这里可以改进一些东西。
然后我查看了这些(大)结构定义,将它们导出到文件 a 和 b 中,经过一些格式化后发现 v2 的唯一区别确实只是之前的扩展:
在 .cc 文件中定义,只有一个变量
iocontrol_data
定义为指向它的指针。该(全局)变量和结构名称都保持不变。将变量声明为静态变量对 cppcheck 没有帮助(但它应该有,对吧?)。我承认这里没有最终的答案。我的直接想法是提出一个 iocontrol typedef,它是两个版本的联合,但我从来都不是联合的粉丝。此外,如果 iocontrols 流被协议化到一个文件中,那么在单独的包含文件中提供数据类型可能会很方便。
我的第一反应是重命名之前的定义。
但我可能会遗漏一些东西?!?
非常感谢
史蒂芬