From: Fergus Henderson <fjh@cs.mu.OZ.AU>
To: Alexandre Oliva <aoliva@redhat.com>
Cc: Jan Hubicka <jh@suse.cz>, Andrew Morton <akpm@digeo.com>,
gcc@gcc.gnu.org
Subject: Re: possible bug
Date: Fri, 31 Jan 2003 10:48:00 -0000 [thread overview]
Message-ID: <20030131052825.GB15725@ceres.cs.mu.oz.au> (raw)
In-Reply-To: <orptqe0yi9.fsf@livre.redhat.lsd.ic.unicamp.br>
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.
next prev parent reply other threads:[~2003-01-31 5:28 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-31 0:33 Andrew Morton
2003-01-31 0:36 ` Jan Hubicka
2003-01-31 0:56 ` Andrew Morton
2003-01-31 8:08 ` Alexandre Oliva
2003-01-31 10:48 ` Fergus Henderson [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-03-26 20:28 Possible Bug Nathan Boley
2011-03-27 7:38 ` Ian Lance Taylor
2011-03-28 11:06 ` Paolo Bonzini
2011-03-28 11:28 ` Richard Guenther
2011-03-28 11:47 ` Paolo Bonzini
2011-03-28 12:14 ` Richard Guenther
2011-03-28 13:37 ` Michael Matz
2011-03-28 13:54 ` Paolo Bonzini
2011-03-28 14:37 ` Richard Guenther
2011-03-29 16:03 ` Nathan Boley
1999-07-25 17:52 possible bug Manush Dodunekov
1999-07-26 10:57 ` Alexandre Oliva
1999-07-27 3:27 ` Manush Dodunekov
1999-07-27 3:37 ` Alexandre Oliva
1999-07-31 23:33 ` Alexandre Oliva
1999-07-31 23:33 ` Manush Dodunekov
1999-07-31 23:33 ` Alexandre Oliva
1999-07-31 23:33 ` Manush Dodunekov
1997-12-12 15:46 Possible Bug Mike Sullivan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030131052825.GB15725@ceres.cs.mu.oz.au \
--to=fjh@cs.mu.oz.au \
--cc=akpm@digeo.com \
--cc=aoliva@redhat.com \
--cc=gcc@gcc.gnu.org \
--cc=jh@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).