Re: [Q] compiler no longer warning about undeclared struct?

From: Andreas Schwab
Date: Thu Jul 28 2011 - 07:10:27 EST


Guennadi Liakhovetski <g.liakhovetski@xxxxxx> writes:

> I always thought you need forward declarations for those, as in
>
> struct yy;
>
> before declaring struct xx above.

You only need that if you would otherwise introduce the struct tag in a
different scope, like prototype scope (which ends at the end of the
prototype).

>> Otherwise you could not define recursive structures as in
>> ---- snip ----
>> struct a {
>> struct *b;
>> };
>> struct b {
>> struct *a;
>> };
>> ---- snip ----
>
> I would add a "struct b;" forward declaration before "struct a".

You can do that, but since a struct definition doesn't introduce a new
scope it is not necessary.

Andreas.

--
Andreas Schwab, schwab@xxxxxxxxxx
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 5EC7 45C6 250E 6F00 984E
"And now for something completely different."
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/