From owner-freebsd-questions Sun Jan 16 12:50:20 2000 Delivered-To: freebsd-questions@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by hub.freebsd.org (Postfix) with ESMTP id 68AC715118 for ; Sun, 16 Jan 2000 12:50:17 -0800 (PST) (envelope-from bright@fw.wintelcom.net) Received: (from bright@localhost) by fw.wintelcom.net (8.9.3/8.9.3) id NAA12168; Sun, 16 Jan 2000 13:12:24 -0800 (PST) Date: Sun, 16 Jan 2000 13:12:24 -0800 From: Alfred Perlstein To: Marty Leisner Cc: "Alexey N. Dokuchaev" , freebsd-questions@FreeBSD.ORG Subject: Re: (void)printf(); (Was: Re: simple c i/o question) Message-ID: <20000116131224.F508@fw.wintelcom.net> References: <20000113030235.Z9397@fw.wintelcom.net> <200001162043.PAA10900@rochester.rr.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <200001162043.PAA10900@rochester.rr.com>; from leisner@rochester.rr.com on Sun, Jan 16, 2000 at 03:43:35PM -0500 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG * Marty Leisner [000116 13:06] wrote: > > Most cases of casting things like printf is to shut up lint. > > IMHO this is very bad practice, you shouldn't have unneeded symbols. > > Just for a quick note, gcc -Wall -W (2.95.2) doesn't complain on > this program: > > : leisner@soyata;cat foo.c > #include > > int main(void) > { > printf("hello world\n"); > exit(0); > } > > I don't know if gcc has an option to flag this...but write uncluttered code. gcc (or maybe some other older compiler) used to be able to flag this, I admit that I don't use it that often, but sometimes it just makes sense. It would probably better serve people if the code in question had a comment explaining _why_ the return value is ignored. -Alfred > Marty Leisner > > > Alfred Perlstein writes on Thu, 13 Jan 2000 03:02:36 PS > T > > * Alexey N. Dokuchaev [000112 23:54] wrote: > > > On Wed, 12 Jan 2000, Naief BinTalal wrote: > > > > > > > On Wed, Jan 12, 2000 at 04:28:23PM +0000, Jonathon McKitrick wrote: > > > > > > > > > > I'm trying to write a hello world program. What is the output > file for > > > > > the console currently being displayed (in other words, the > screen)? > > > > > I've tried printf, and fprintf to stdout and stderr. > > > > > > > > #include > > > > > > > > int > > > > main(void) > > > > { > > > > (void)fprintf(stdout,"Hello World\n"); > > > > return 0; > > > > } > > > > > > > > > > While browsing thru the source code of almost anything in FreeBSD, > I've > > > noticed that (type)function(parameters); syntax. Why not just to > write > > > function(paramenters). Like in the prev example, what's wrong with > simple > > > printf(blahblah); but (void)printf(blahblah); ? > > > > Nothing really, it's my preference to only use void when I mean: > > > > "i know this function returns something that may be interesting, but > frankly > > I don't care at this point" > > > > using it for things like printf is a bit much, but it sort of let's the > > next guy know that you didn't miss something. > > > > I also remember hearing that older compilers had an option to complain > > about code that didn't do something with return values. > > > > -Alfred > > > > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > > with "unsubscribe freebsd-questions" in the body of the message > -- -Alfred Perlstein - [bright@wintelcom.net|alfred@freebsd.org] To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message