From owner-freebsd-hackers@FreeBSD.ORG Thu Aug 7 17:19:23 2008 Return-Path: Delivered-To: hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3861A1065672; Thu, 7 Aug 2008 17:19:23 +0000 (UTC) (envelope-from scf@FreeBSD.org) Received: from mail.farley.org (farley.org [67.64.95.201]) by mx1.freebsd.org (Postfix) with ESMTP id F16B98FC0A; Thu, 7 Aug 2008 17:19:22 +0000 (UTC) (envelope-from scf@FreeBSD.org) Received: from thor.farley.org (HPooka@thor.farley.org [192.168.1.5]) by mail.farley.org (8.14.3/8.14.3) with ESMTP id m77HJK9E008012; Thu, 7 Aug 2008 12:19:21 -0500 (CDT) (envelope-from scf@FreeBSD.org) Date: Thu, 7 Aug 2008 12:19:20 -0500 (CDT) From: "Sean C. Farley" To: Jeremy Chadwick In-Reply-To: <20080807170235.GA39461@eos.sc1.parodius.com> Message-ID: References: <489B0ACD.80008@kovesdan.org> <489B22BD.5050109@kovesdan.org> <20080807170235.GA39461@eos.sc1.parodius.com> User-Agent: Alpine 1.10 (BSF 962 2008-03-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Spam-Status: No, score=-4.4 required=3.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on mail.farley.org Cc: hackers@FreeBSD.org Subject: Re: strange issue reading /dev/null X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Aug 2008 17:19:23 -0000 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