1

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.

Bob
  • 4,576
  • 7
  • 39
  • 107
  • @4386427 I know the reason why `cflow` thinks it's being redefined: it doesn't understand the `typedef struct` construct. – Bob Dec 05 '17 at 19:01
  • 1
    I think you're jumping to conclusions. I don't know why `cflow` is saying that `a` is redefined, but it's unlikely that a tool in widespread use would fail to understand a feature that's been in standard C for decades. I don't get that error using cflow 1.4 on Ubuntu. What does `cflow --version` print? – Keith Thompson Dec 05 '17 at 19:38
  • @KeithThompson I'm using `cflow` 1.5 on windows. I'll try it with 1.4. Also, in Linux, the [configuration values are read from an environment variable and .cflowrc](https://www.gnu.org/software/cflow/manual/cflow.html#Configuration). So, yours may be loading in some config options that tell `cflow` how to parse the `typedef struct`. I'll build 1.4 and get back – Bob Dec 05 '17 at 19:43

1 Answers1

3

This is clearly a bug in cflow.

I just built cflow versions 1.3, 1.4, and 1.5 on my system (Ubuntu 17.04). Versions 1.3 and 1.4 do not exhibit the problem you describe. Version 1.5 does.

Here's a simpler test case that exhibits the problem:

$ 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 and separate namespaces for different structure types have been features of C for about three decades. It's not plausible that cflow would fail to support them -- and in fact earlier versions handle them with no problem.)

As a workaround, use cflow 1.4. I also suggest submitting a bug report. It doesn't appear that this one has been reported. (The OP has now reported it to the bug-cflow@gnu.org mailing list and received an acknowledgement.)

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • If you like, I can submit a bug report myself. – Keith Thompson Dec 05 '17 at 20:16
  • I just did it. Unfortunately, version `1.4` doesn't output symbols when using `-i x` but it's preferable to the other behavior. – Bob Dec 05 '17 at 20:39
  • @Adrian: I don't see it on the [Bugzilla page](https://savannah.gnu.org/bugs/?group=cflow). – Keith Thompson Dec 05 '17 at 20:52
  • 1
    I sent it at 3:38PM EST title `Bug 1.5: typedef struct doesn't result in separate namespace` to `bug-cflow@gnu.org`. It's the same address as for the mailing list for help so it's moderated. – Bob Dec 05 '17 at 20:55
  • 1
    I just got an email from the guy saying "thanks for reporting it" – Bob Dec 05 '17 at 20:59
  • 1
    @Adrian: I don't know how that project manages bugs internally. As long as they've been informed, whether via a Bugzilla ticket or an e-mail to the appropriate list, I'm not inclined to worry about it. I've added links to your report and the acknowledgement. – Keith Thompson Dec 06 '17 at 19:15