Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Aug 2008 12:19:20 -0500 (CDT)
From:      "Sean C. Farley" <scf@FreeBSD.org>
To:        Jeremy Chadwick <koitsu@FreeBSD.org>
Cc:        hackers@FreeBSD.org
Subject:   Re: strange issue reading /dev/null
Message-ID:  <alpine.BSF.1.10.0808071216150.2133@thor.farley.org>
In-Reply-To: <20080807170235.GA39461@eos.sc1.parodius.com>
References:  <489B0ACD.80008@kovesdan.org> <alpine.BSF.1.10.0808071058020.1056@thor.farley.org> <489B22BD.5050109@kovesdan.org> <alpine.BSF.1.10.0808071150460.2133@thor.farley.org> <20080807170235.GA39461@eos.sc1.parodius.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 7 Aug 2008, Jeremy Chadwick wrote:

> On Thu, Aug 07, 2008 at 11:54:10AM -0500, Sean C. Farley wrote:
>> On Thu, 7 Aug 2008, Gabor Kovesdan wrote:
>>> Sean C. Farley ha scritto:
>>>> You are testing c which has not been set.  It works OK if you set c
>>>> then do the test:
>>>>
>>>> +       c = fgetc(f);
>>>>         if (c != EOF)
>>>> -               printf("%c\n", fgetc(f));
>>>> +               printf("%c\n", c);
>>> Yes, you are right, this is what I meant, I'm just a bit
>>> disorganised....
>>> Thanks!
>>
>> You are welcome.
>>
>> Actually, what I found odd was that the base gcc did not warn about
>> using an uninitialized variable using -Wall.
>
> Probably because you didn't use -O.  -Wall includes -Wuninitialized,
> but -Wuninitialized only applies if you use optimisation.  gcc won't
> bail if you use -Wall without -O, for obvious reasons.  Case in point:

You are correct; I did not use -O.

> $ gcc -Wall -o x x.c
> x.c: In function 'main':
> x.c:14: warning: control reaches end of non-void function
>
> $ gcc -Wuninitialized -o x x.c
> cc1: warning: -Wuninitialized is not supported without -O

Heh.

> $ gcc -Wall -O -o x x.c
> x.c: In function 'main':
> x.c:14: warning: control reaches end of non-void function
> x.c:12: warning: 'c' is used uninitialized in this function
>
> gcc -- finding new ways every day to drive programmers crazy.  :-)

Grr!  Optimization should not be a requirement for checking for
uninitialized variables.  Yes, gcc adds "fun" to development.

Sean
-- 
scf@FreeBSD.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?alpine.BSF.1.10.0808071216150.2133>