Re: [RFC] struct *_struct

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 05, 2010 at 08:57:13PM -0700, Michael Witten wrote:
> On Wed, Aug 4, 2010 at 14:24, Junio C Hamano <gitster@xxxxxxxxx> 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@xxxxxxxxx> 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.

> 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 Witten

I agree here too. By the way, my comments were mostly against
specifically "typedef foo struct foo", since that what was
specifically mentioned.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]