Pointer to undeclared structure-type considered ok?

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

 



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;
    
    int
    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):

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

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

    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?

/npat


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux