From: "E. Weddington" <ericw@evcohs.com>
To: Dmitry Antipov <antipov@dev.rtsoft.ru>
Cc: gcc@gcc.gnu.org
Subject: Re: Dubious "'foo' might be used uninitialized in this function" message
Date: Tue, 14 Dec 2004 16:40:00 -0000 [thread overview]
Message-ID: <41BF17A8.3080906@evcohs.com> (raw)
In-Reply-To: <41BF1207.2040102@dev.rtsoft.ru>
Dmitry Antipov wrote:
> When compiling the following program,
>
> #include <unistd.h>
>
> int f (int x, int y)
> {
> int z;
>
> if (x)
> z = getppid ();
> y = getpid ();
> if (x)
> y += z;
> return x + y + z;
> }
>
> GCC (with '-Wall') always says:
>
> w.c: In function `f':
> w.c:5: warning: 'z' might be used uninitialized in this function
>
> which is not true.
>
> Here 'z' is initialized under 'if (x)' condition, and 'z' always used
> under
> 'if (x)' condition. Also, it's clear that 'x' isn't accessed between
> 'if (x)',
> so it's impossible to access uninitialized 'z'.
>
> Is it reasonable to learn GCC do more analysis in attempt to avoid
> warning in this case ? How is it complex ?
>
Even if you rearranged the code to remove your warning above:
int f (int x, int y)
{
int z;
y = getpid ();
if (x)
{
z = getppid ();
y += z;
}
return x + y + z;
}
You'll still get an uninitialized variable warning for your return
statement, where you do use z uninitialized.
next prev parent reply other threads:[~2004-12-14 16:40 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-14 15:23 Dmitry Antipov
2004-12-14 16:40 ` E. Weddington [this message]
2004-12-14 17:00 ` Nathan Sidwell
2004-12-15 9:00 ` Dmitry Antipov
2004-12-15 10:02 ` Nathan Sidwell
2004-12-15 12:06 ` Robert Dewar
2004-12-15 17:33 ` Florian Weimer
2004-12-15 17:34 ` Robert Dewar
2004-12-15 17:52 ` Florian Weimer
2004-12-15 18:00 ` Robert Dewar
2004-12-15 17:33 ` Joe Buck
2004-12-15 18:03 ` Dave Korn
2004-12-15 18:09 ` Robert Dewar
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=41BF17A8.3080906@evcohs.com \
--to=ericw@evcohs.com \
--cc=antipov@dev.rtsoft.ru \
--cc=gcc@gcc.gnu.org \
/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).