Jeff Abrahamson on Sun, 8 Dec 2002 17:01:05 -0500


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

[PLUG] C question: struct pointer error


I wonder if someone can help me see what I'm missing.

The following code snippet yields a warning and an error. I don't
think it should. Am I confused, or is gcc?

    int foo(struct bar *b);

    typedef struct bar {
	    int a;
    } Bar;

    foo(Bar *b)
    {
	    return 0;
    }

 jeff@diderot:scratch $ gcc  -Wall -c struct2.c
 struct2.c:1: warning: `struct bar' declared inside parameter list
 struct2.c:1: warning: its scope is only this definition or declaration, which is probably not what you want.
 struct2.c:8: warning: return-type defaults to `int'
 struct2.c:8: conflicting types for `foo'
 struct2.c:1: previous declaration of `foo'
 jeff@diderot:scratch $ 

At line 1, the size of the structure is not needed, so the declaration
should be ok by my reading of K&R. Then at line 8, Bar is a synonym
for struct bar, so it should be ok, again as per my understanding of
K&R (by which I mean the ANSI C version, of course).

 jeff@diderot:scratch $ gcc -v
 Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
 gcc version 2.95.4 20011002 (Debian prerelease)
 jeff@diderot:scratch $ 

-- 
 Jeff

 Jeff Abrahamson  <http://www.purple.com/jeff/>
 GPG fingerprint: 1A1A BA95 D082 A558 A276  63C6 16BF 8C4C 0D1D AE4B

Attachment: pgpsFfyTcxbK5.pgp
Description: PGP signature