Pointer to undeclared structure-type considered ok?

Nick Patavalis npat@inaccessnetworks.com
Wed Feb 2 14:23:00 GMT 2005

Accidentally I attempted to compile a program like the one shown
below, and I was totally amazed by the fact that the compiler produced
*no errors* and *no warnings*. Is this valid C? Wouldn't at least a
warning be in order here?

    #include <stdlib.h>
    #include <stdio.h>
    struct foo {
        int a;
        struct bar *b;
    struct foo foo;
    main (void)
        foo.a = 0;
        foo.b = NULL;
        printf("foo.a = %d\n", foo.a);
        printf("foo.b = %p\n", foo.b);
        return 0;

and compiled like this:

    gcc -Wall tst.c -o tst
    [ ... no errors or warnings!! ... ]

and also runs fine (which is not surprising):

    foo.a = 0
    foo.b = (nil)

I used GCC-3.3.4, the one that comes with the current debian-sarge,

    gcc --version
    gcc (GCC) 3.3.4 (Debian 1:3.3.4-13)
    Copyright (C) 2003 Free Software Foundation, Inc.

Is this a bug in GCC?


More information about the Gcc-help mailing list