Search code examples
cgtkconventions

What is the point of the _StructName convention in C?


After reading some source from the GTK+ library, I have encountered what I perceive to be a rather odd piece of code:

typedef struct _GtkWidgetClass GtkWidgetClass;

...

struct _GtkWidgetClass
{
    ...
};

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

typedef struct
{
    ...
} GtkWidgetClass;

I feel like I am missing something...
If someone could fill me in on as to why GTK (or for that matter, any other code) is written in this manner, it would be much appreciated.

Thanks in advance


Solution

  • From a strict coding standpoint, it has no purpose. However, in header files it can serve as a type of interface definition, which list the "public" interface of GTK+. By the way, this style follows other GNU libraries.

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