Author Topic: Don't understand the "Multiples matches" of "Find declaration"  (Read 3543 times)

Offline Teybeo

  • Multiple posting newcomer
  • *
  • Posts: 14
Don't understand the "Multiples matches" of "Find declaration"
« on: January 27, 2013, 03:06:01 pm »
I always declare my structures like this:
Code
typedef struct Thing {
    int var;
} Thing;

When I want to go to its declaration, I right-click and choose "Find declaration of: 'Thing' ".

But then an intermediate window pop telling me there are multiples matches:
Code
class Thing {...}
and
Code
typedef Thing Thing

  • 1. Why does it print that 'class' word which don't exist in C ?
  • 2. Why the second line is "typedef Thing Thing" ? Didn't I wrote a "typedef struct Thing Thing ?"
     

And finally, those multiple matches are obviously redundant in my case and that popping window bothers me.
Is there something that can be made (both in my coding or in CodeBlocks) to prevent it ?

Edit: Win7 64 bits, CB 12.11
« Last Edit: January 27, 2013, 03:25:17 pm by Teybeo »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Don't understand the "Multiples matches" of "Find declaration"
« Reply #1 on: January 27, 2013, 04:33:03 pm »
The parser in C::B is more C++ centric than C. So for a C++ there are two types Thing and the typedef Thing.

As far as I know the proper way to define structs in C is typedef struct { } Thing;
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

zabzonk

  • Guest
Re: Don't understand the "Multiples matches" of "Find declaration"
« Reply #2 on: January 27, 2013, 04:36:17 pm »
Quote
And finally, those multiple matches are obviously redundant in my case

Not really, the typedef name and the struct name exist in different namespaces in C, so you really do have two different names. I agree that that one of them should really be "struct Thing", but I guess that is just a quirk of the parser that C::B uses which treats structs and classes as basically the same thing (as they are in C++).

Offline Teybeo

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: Don't understand the "Multiples matches" of "Find declaration"
« Reply #3 on: January 27, 2013, 06:50:28 pm »
As far as I know the proper way to define structs in C is typedef struct { } Thing;

But when I do this, I can no longer make forward declarations of the struct because it is anonymous :/

Quote from: Neil Butterworth
Quote from: Teybeo
And finally, those multiple matches are obviously redundant in my case
Not really, ...

I meant that in my utilization of a typedef just to not having to write the struct keyword everywhere, the pop-up window is totally useless and annoying. I understand that there are 2 different things :).
« Last Edit: January 27, 2013, 06:53:53 pm by Teybeo »

Offline p2rkw

  • Almost regular
  • **
  • Posts: 142
Re: Don't understand the "Multiples matches" of "Find declaration"
« Reply #4 on: January 27, 2013, 07:39:24 pm »
So try:
Code
typedef struct {
    int var;
} Thing;

zabzonk

  • Guest
Re: Don't understand the "Multiples matches" of "Find declaration"
« Reply #5 on: January 27, 2013, 08:08:40 pm »
Quote
I meant that in my utilization of a typedef just to not having to write the struct keyword everywhere, the pop-up window is totally useless and annoying.

Maybe so, but it's expecting a bit too much for C::B to know that. For example, if your code was:

Code
struct Thing {
     int val;
};

// 1000 lines of code here

typedef struct Thing Thing;


then presumably you would want to have both names available.