【问题标题】:gnu cflow - not recognizing "typedef struct"gnu cflow - 无法识别“typedef struct”
【发布时间】: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 构造。
  • 我认为你是在草率下结论。我不知道为什么cflowa 被重新定义了,但是一个广泛使用的工具不太可能无法理解标准C 几十年来的一个特性。我在 Ubuntu 上使用 cflow 1.4 没有收到该错误。 cflow --version 打印什么?
  • @KeithThompson 我在 Windows 上使用 cflow 1.5。我会用1.4试试。此外,在 Linux 中,configuration values are read from an environment variable and .cflowrc。因此,您的可能正在加载一些配置选项,告诉cflow 如何解析typedef struct。我将构建 1.4 并返回

标签: c call-graph cflow


【解决方案1】:

这显然是cflow 中的一个错误。

我刚刚在我的系统 (Ubuntu 17.04) 上构建了 cflow 版本 1.3、1.4 和 1.5。版本 1.3 和 1.4 没有出现您描述的问题。 1.5 版可以。

这是一个显示问题的更简单的测试用例:

$ cat c.c
typedef struct type1 { int a; } type1;
typedef struct type2 { int a; } type2;
$ cflow --version | head -n 1
cflow (GNU cflow) 1.5
$ cflow c.c
cflow:c.c:2: a redefined
cflow:c.c:1: this is the place of previous definition
$ 

typedef struct 和不同结构类型的单独命名空间已经成为 C 语言的特性大约三年了。cflow 无法支持它们是不合理的——事实上,早期版本可以毫无问题地处理它们。)

作为一种解决方法,请使用cflow 1.4。我还建议提交错误报告。这个好像没有报道。 (OP 现在有reported itbug-cflow@gnu.org 邮件列表并收到acknowledgement。)

【讨论】:

  • 如果您愿意,我可以自己提交错误报告。
  • 我刚刚做到了。不幸的是,1.4 版本在使用 -i x 时不输出符号,但它比其他行为更可取。
  • 我在美国东部标准时间下午 3:38 将它发送到标题 Bug 1.5: typedef struct doesn't result in separate namespacebug-cflow@gnu.org。它与寻求帮助的邮件列表的地址相同,因此已被审核。
  • 我刚收到一封电子邮件,上面写着“感谢报告”
  • @Adrian:我不知道该项目如何在内部管理错误。只要他们被告知,无论是通过 Bugzilla 票证还是通过电子邮件发送到相应的列表,我都不会担心。我已添加指向您的报告和致谢的链接。
猜你喜欢
  • 2011-05-06
  • 1970-01-01
  • 2015-04-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多