【发布时间】:2017-12-05 18:40:35
【问题描述】:
GNU cflow 分析一组 C 源文件并打印图表,绘制程序内的控制流图表。
我的.c 或.cpp 文件
typedef struct _type_1{
int a;
} type_1_t;
typedef struct _type_2{
int a;
} type_2_t;
int main()
{
type_1_t t1;
type_2_t t2;
t1.a = 55;
t2.a = 99;
return 0;
}
命令为cflow.exe test.c -i s -i x > test.graph 2>&1,输出为:
cflow.exe:test.c:7: a redefined
cflow.exe:test.c:2: this is the place of previous definition
main() <int main () at test.c:11>:
type_1_t <type_1_t at test.c:3>
t1
type_2_t <type_2_t at test.c:8>
t2
问题
为什么说“重新定义”?
只能是因为它无法识别typedef struct 构造,所以我该如何解决?
更新
我用--debug=1 再次运行cflow,它给了我这个:
test.c:3: type _type_1
test.c:3: a/-1 defined to int a
test.c:3: type_1_t/-1 defined to type_1_t
test.c:8: type _type_2
cflow.exe:test.c:7: a redefined
cflow.exe:test.c:2: this is the place of previous definition
main() <int main () at test.c:15>:
type_1_t <type_1_t at test.c:3>
t1
type_2_t <type_2_t at test.c:8>
t2
f1() <int f1 () at test.c:10>
test.c:8: a/-1 defined to int a
test.c:8: type_2_t/-1 defined to type_2_t
test.c:11: f1/0 defined to int f1 ()
test.c:16: main/0 defined to int main ()
正如我们所怀疑的:它没有处理每个 struct 。 . .作为一个结构,即能够在两个不同的结构中拥有完全相同的标识符。
那么如何解决这个问题?我正在通过电子邮件发送cflow 邮件列表。希望很快能收到回复。在那之前,我将尝试使用syntactic classes 看看我是否无法触发正确的行为。
如果我从邮件列表中得到回复,我会发布我自己的答案。
【问题讨论】:
-
@4386427 我知道
cflow认为它被重新定义的原因:它不理解typedef struct构造。 -
我认为你是在草率下结论。我不知道为什么
cflow说a被重新定义了,但是一个广泛使用的工具不太可能无法理解标准C 几十年来的一个特性。我在 Ubuntu 上使用 cflow 1.4 没有收到该错误。cflow --version打印什么? -
@KeithThompson 我在 Windows 上使用
cflow1.5。我会用1.4试试。此外,在 Linux 中,configuration values are read from an environment variable and .cflowrc。因此,您的可能正在加载一些配置选项,告诉cflow如何解析typedef struct。我将构建 1.4 并返回
标签: c call-graph cflow