Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 16 Jan 2000 15:43:35 -0500
From:      "Marty Leisner" <leisner@rochester.rr.com>
To:        Alfred Perlstein <bright@wintelcom.net>
Cc:        "Alexey N. Dokuchaev" <danfe@ssc.nsu.ru>, freebsd-questions@FreeBSD.ORG, leisner@rochester.rr.com
Subject:   Re: (void)printf(); (Was: Re: simple c i/o question) 
Message-ID:  <200001162043.PAA10900@rochester.rr.com>
In-Reply-To: Your message of "Thu, 13 Jan 2000 03:02:36 PST." <20000113030235.Z9397@fw.wintelcom.net> 

next in thread | previous in thread | raw e-mail | index | archive | help

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 <stdio.h>

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.
Marty Leisner


Alfred Perlstein <bright@wintelcom.net> writes  on Thu, 13 Jan 2000 03:02:36 PS
T
     > * Alexey N. Dokuchaev <danfe@ssc.nsu.ru> [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 <stdio.h>
     > > > 
     > > >   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




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




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