Re: Style convention question
- From: Owen Taylor <otaylor redhat com>
- To: gtk-devel-list gnome org
- Subject: Re: Style convention question
- Date: 09 Mar 2001 12:39:41 -0500
Derek Simkowiak <dereks realloc net> writes:
> This is a quickie. My apologies if it's not the best list for
> this, but I know that the right people are here :).
>
> Why does Glib do this:
>
> typedef struct _GFoo GFoo;
> struct _GFoo {
> /* [...] */
> };
>
> ...instead of the more compact
>
> typedef struct {
> /* [...] */
> } GFoo;
>
> I don't see the "struct _GFoo"s anywhere in the code. I asked a
> veteran Unix programmer and he didn't know of any compilers that had
> problems with the "typedef struct { /* stuff */ } GFoo;" format.
>
> Is this just a religous thing? Or is there some
> backwater-compiler that doesn't support the latter format?
The reason is that sometimes you need forward declarations:
typedef struct _A A;
typedef struct _B B;
struct _A {
B *b;
};
struct _B {
A *a;
};
And instead of worrying about the order of structure definitions, and
what ones need to be forward declared and what ones don't, we, by
convention, forward declare everything.
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]