GNU cflow
analyzes a collection of C source files and prints a graph, charting control flow within the program.
My .c
or .cpp
file
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;
}
The command is cflow.exe test.c -i s -i x > test.graph 2>&1
and the output is:
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
QUESTION
Why does it say "a redefined"?
It can only be because it doesn't recognize the typedef struct
construct so how do I fix it?
UPDATE
I ran cflow
again with --debug=1
and it gave me this:
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 ()
Just as we suspected: it's not treating each struct . . . as a struct i.e. the ability to have the exact same identifier in two different structs.
So how to fix this? I'm emailing cflow
mailing list. Hopefully will hear back soon. Until then, I'm going to play around with the syntactic classes and see if I can't trigger the correct behavior.
I'll post my own answer if I get an answer back from mailing list.