Re: [RFC] struct *_struct
- From
Jared Hance <jaredhance@gmail.com>
- Date
- Aug 6, 2010, 12:29 UTC
- Message-ID
- <20100806122920.GA2346@localhost.localdomain>
- In-Reply-To
- <4c5b8819.4f3fdc0a.14ad.22b1@mx.google.com>
On Thu, Aug 05, 2010 at 08:57:13PM -0700, Michael Witten wrote:
Show 13 quoted lines
> On Wed, Aug 4, 2010 at 14:24, Junio C Hamano <gitster@pobox.com> wrote:
> >>> I hate... "typedef foo struct foo"
>
> On Thu, Aug 05, 2010 at 11:20:14AM -0500, Michael Witten wrote:
> >> How come?
>
> On Thu, Aug 5, 2010 at 17:43, Jared Hance <jaredhance@gmail.com> wrote:
> Those are valid points, but I'm not sure they have a practical basis;
> your problems are largely solved by capitalization conventions
> (which essentially provide shorter replacements for `struct '):
>
> typedef struct { /* ... */ } Foo;
> Foo foo;I agree, thats much better. The original hate was on "struct foo foo". For some reason, I still prefer the version without the typedef, though.
Show 68 quoted lines
> Unfortunately, such conventions don't enjoy the benefit of semantic
> protection. However, language-aware source navigation tools (like ctags)
> should be able to solve that problem and are probably more efficient
> in navigation time than grepping.
>
> Moreover, the form:
>
> foo foo;
>
> is probably not that problematic in practice; it's presence is likely
> to be short lived for 2 reasons:
>
> * Subjectively : everyone thinks it looks awful.
> * Objectively : It's technically constrained.
>
> The typedef declaration:
>
> typedef /*type*/ foo;
>
> introduces the typedef name `foo' into the `ordinary identifier'
> name space; consequently, the declaration:
>
> foo foo;
>
> cannot even occur in the same scope as the typdef, and when
> it does occur in an inner scope, it hides the original typdef
> name `foo' for all subsequent inner scopes:
>
> typedef struct {char x;} foo;
>
> foo foo; // error: attempt to redeclare `foo'.
> foo a;
>
> int main()
> {
>
> foo foo; // OK; hide typedef name with variable `foo'
> foo b; // error: `foo' is not a type.
>
> {
>
> foo c; // error: `foo' is not a type.
>
> typedef struct {char x;} foo; // OK; hide variable `foo'
>
> foo foo; // error: attempt to redeclare `foo'
> foo d;
>
> d = a; // error: anonymous structs are always different types.
>
> {
> foo foo; // OK; hide typedef name with variable `foo'
> d = foo; // OK; same type
> foo e; // error: `foo' is not a type.
> }
>
> {
> foo foo; // OK; hide typedef name with variable `foo'
> d = foo; // OK; same type
> foo f; // error: `foo' is not a type.
> }
>
> }
>
> }
>
> Sincerely,
> Michael WittenI agree here too. By the way, my comments were mostly against specifically "typedef foo struct foo", since that what was specifically mentioned.