Re: struct interdependenci es
Chris Croughton wrote:[color=blue]
> On Mon, 18 Apr 2005 11:40:30 +1000, Russell Shaw
> <rjshawN_o@s_pa m.netspace.net. au> wrote:
>
>[color=green]
>>Old Wolf wrote:
>>[color=darkred]
>>>Chris Torek wrote:
>>>
>>>
>>>>Stop using typedefs.
>>>
>>>One problem I find when using struct tags rather than typedefs:
>>>
>>> struct gargleblaster
>>> {
>>> int whatever;
>>> };
>>>
>>> void foo(struct garbleglaster *ptr);
>>>
>>>will raise no compiler errors, until later on when I try to
>>>define foo() and assign ptr, then it will tell me that ptr's
>>>type is incompatible with what I'm assigning it to. Whereas:
>>>
>>> typedef struct { int whatever; } hyperspacebypas s;
>>> void bar(hypespaceby pass *ptr);
>>>
>>>will cause a compiler error right then and there.[/color]
>>
>>Can't see why the latter should be in error. I was always using the
>>same thing in gcc.[/color]
>
> Did you spot the error in the first example using struct? The error is
> the same (mistyped identifier), but in the first case the compiler will
> just say "OK, I'm using a structure with incomplete type, no problem"
> until you try to access something in that structure or pass a pointer to
> a structure with the correct name to the function. And then it can take
> ages to spot cause of the error, because it's subtle and removed from
> the place of the actual error. That's why using the typedef is better,
> the compiler will spot immediately "hypespacebypas s is not a type".[/color]
I have an annoying problem of reading by patterns, and if the patterns
look similar, i don't see the problem even after reading multiple times.
If i *know* the error is in that location, i start reading letter by letter
(i got aspergers a bit).
Chris Croughton wrote:[color=blue]
> On Mon, 18 Apr 2005 11:40:30 +1000, Russell Shaw
> <rjshawN_o@s_pa m.netspace.net. au> wrote:
>
>[color=green]
>>Old Wolf wrote:
>>[color=darkred]
>>>Chris Torek wrote:
>>>
>>>
>>>>Stop using typedefs.
>>>
>>>One problem I find when using struct tags rather than typedefs:
>>>
>>> struct gargleblaster
>>> {
>>> int whatever;
>>> };
>>>
>>> void foo(struct garbleglaster *ptr);
>>>
>>>will raise no compiler errors, until later on when I try to
>>>define foo() and assign ptr, then it will tell me that ptr's
>>>type is incompatible with what I'm assigning it to. Whereas:
>>>
>>> typedef struct { int whatever; } hyperspacebypas s;
>>> void bar(hypespaceby pass *ptr);
>>>
>>>will cause a compiler error right then and there.[/color]
>>
>>Can't see why the latter should be in error. I was always using the
>>same thing in gcc.[/color]
>
> Did you spot the error in the first example using struct? The error is
> the same (mistyped identifier), but in the first case the compiler will
> just say "OK, I'm using a structure with incomplete type, no problem"
> until you try to access something in that structure or pass a pointer to
> a structure with the correct name to the function. And then it can take
> ages to spot cause of the error, because it's subtle and removed from
> the place of the actual error. That's why using the typedef is better,
> the compiler will spot immediately "hypespacebypas s is not a type".[/color]
I have an annoying problem of reading by patterns, and if the patterns
look similar, i don't see the problem even after reading multiple times.
If i *know* the error is in that location, i start reading letter by letter
(i got aspergers a bit).
Comment