Why does this compile?

Bakul Shah bakul at bitblocks.com
Tue Sep 26 05:02:06 UTC 2017


On Mon, 25 Sep 2017 21:38:33 -0700 Russell Haley <russ.haley at gmail.com> wrote:
Russell Haley writes:
> 
> int main()
> {
>     struct in_pktinfo;
>     return 0;
> }
> 
> This compiles on FreeBSD current and apparently on 11 too. That's a
> bad thing because it's supposed to fail. I checked in.h and there is
> no struct for in_pktinfo. Not surprisingly, if I remove the include
> altogether, it still compiles.
> 
> I assume then that the original author made a mistake? My C is too
> weak and most of my searches don't turn up anything close to what I'm
> looking for.
> 
> Any suggestions would be awesome.  :)

C allows struct forward references. Mainly so that you can
declare pointers to them (and the actual struct defn may be in
another file). As long as you don't dereference such a ptr in
the first file, the cmompiler won't throw a fit.

If you want to generate an error, create a variable in main():

	struct in_pktinfo foo;


More information about the freebsd-arm mailing list