What's the point of convention for _StructName in C?

After reading some source from the GTK + library, I came across what I think is a rather strange piece of code:

typedef struct _GtkWidgetClass GtkWidgetClass;

...

struct _GtkWidgetClass
{
    ...
};

      

What I don't understand about this code is why it is not written like this:

typedef struct
{
    ...
} GtkWidgetClass;

      

I feel like I'm missing something ...
If someone can fill me in on why exactly GTK (or, for that matter, any other code) is written this way, it would be very helpful.

Thank you in advance

+3


source to share


2 answers


From a strict coding point of view, it doesn't make any sense. However, in header files, it can serve as an interface definition type that renders the "public" GTK + interface. By the way, this style follows other GNU libraries.



Anyway, I think we can safely say that with modern C compilers and tools, it doesn't really make much sense, but GTK + is not really a new library, so it may contain some archaic conventions.

+6


source


In the first case, you can use a (typedefed) name struct

for the member:

typedef struct _node node;

struct _node
{
    int value;
    node *next; /* valid */
};

      




typedef struct
{
    int value;
    node *next; /* not valid (unknown type name ‘node’) */
} node;

      

+3


source







All Articles