gcc-20001027: Funny business with types on return

Joseph S. Myers jsm28@cam.ac.uk
Sat Oct 28 15:36:00 GMT 2000

On Sat, 28 Oct 2000, Horst von Brand wrote:

> The following gets the bogus warning:
> /tmp/tst.c:7: warning: return from incompatible pointer type
> struct {
>    char name[8];
> } a;
> char *f()
> {
>      return &a.name;
> }

Not a bug.  a.name has type "array of char"; as the operand of & it does
not decay to a pointer, so &a.name has type "pointer to array of char".
This type isn't compatible with "pointer to char" according to the rules
for function returns and assignments in (C99), hence the warning,
which is given by all of, 2.95.2 and current CVS.  You want
"return a.name;"; there, a.name will decay to type "pointer to char".

Joseph S. Myers

More information about the Gcc-bugs mailing list