This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: possible bug
On 31-Jan-2003, Alexandre Oliva <aoliva@redhat.com> wrote:
> On Jan 30, 2003, Jan Hubicka <jh@suse.cz> wrote:
>
> >> char *zot(void)
> >> {
> >> return ({foo(); 0; });
> >> }
> >> mnm:/home/akpm> /usr/local/gcc-3.2.1/bin/gcc -O -Wall -c t.c
> >> t.c: In function `zot':
> >> t.c:10: warning: return makes pointer from integer without a cast
>
> >> I think the warning is bogus?
No, the warning is valid.
The function body calls foo(), evaluations the expression `0' with type
`int', and then converts the `int' to `char *' without a cast.
> > I think the value of ({foo(); 0; }) is zero (value of last statement,
> > if I recall the definition), so it is corect.
>
> But then, zero is a NULL pointer constant, isn't it? At least in C++,
> a warning would have been very inappropriate. I don't think one for C
> is.
`0' is a null pointer constant. But `{foo(); 0;}' is not.
And it is the latter which is being converted to a pointer.
The code shown here is exactly analagous to
char *zot(void)
{
return (foo(), 0);
}
except that it uses a GNU C statement-expression instead of a
comma-expression. In both cases, the `0' expression does not itself occur
in a context in which that `0' expression itself is being converted to
a pointer; instead, the `0' expresion itself has type `int',
and the more complicated expression containing it, which is not
a null pointer constant, is the one that is being converted to
a pointer. Since the more complicated expression is not itself
a null pointer constant, a diagnostic is required.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.