There is only one way to declare a struct
in C, using the struct
keyword, optionally followed by the name of the structure, then followed by the member fields list in braces. So you could have:
struct point_st {
int x, y;
};
Here point_st
is the name (or tag) of your structure. Notice that structure names have a different namespace in C than types (this is different in C++). So I have the habit of suffixing structure names with _st
as shown above.
You can (independently) define a type name using typedef, e.g.
typedef struct point_st Point;
(you can use typedef
on any C type, BTW).
For exemple Gtk and Glib has a lot of opaque types which are such opaque structures; only the implementation knows and cares about the structure members.
Of course the compiler needs to know the field of a structure to allocate it; but if you only use pointers to an opaque structure, you don't need to declare the structure (i.e. its fields in braces).