News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Don't understand the "Multiples matches" of "Find declaration"

Started by Teybeo, January 27, 2013, 03:06:01 PM

Previous topic - Next topic

Teybeo

I always declare my structures like this:

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:
class Thing {...}
and
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

oBFusCATed

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

QuoteAnd 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++).

Teybeo

Quote from: oBFusCATed on January 27, 2013, 04:33:03 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: TeybeoAnd 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 :).

p2rkw


zabzonk

QuoteI 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:

struct Thing {
     int val;
};

// 1000 lines of code here

typedef struct Thing Thing;



then presumably you would want to have both names available.