Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 Jan 2000 10:22:34 -0500
From:      Naief BinTalal <naief@cyfari.com>
To:        "Alexey N. Dokuchaev" <danfe@ssc.nsu.ru>
Cc:        freebsd-questions@FreeBSD.org
Subject:   Re: (void)printf(); (Was: Re: simple c i/o question)
Message-ID:  <20000113102234.A45156@cyfari.com>
In-Reply-To: <Pine.LNX.4.10.10001131324520.22433-100000@inet.ssc.nsu.ru>; from danfe@ssc.nsu.ru on Thu, Jan 13, 2000 at 01:28:08PM %2B0600
References:  <20000112114019.A93129@cyfari.com> <Pine.LNX.4.10.10001131324520.22433-100000@inet.ssc.nsu.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Jan 13, 2000 at 01:28:08PM +0600, Alexey N. Dokuchaev 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); ?
> 
  Hi Alexey
  When you write (void)function(Whatever); you are casting the return
  value to void. This _explicitly_ says that you the programmer know
  that the function returns a value but choose to ignore it.

  That's all. It's a better way of programming. 

  By the way I can tell that you have reached that level where obscure
  language features that you don't know bother you ;>. Well the only way
  is to read the standard or you take a look at books which go through the
  standard bit by bit.

  A good book on this is "C, A Reference Manual" by Samuel P. Harbison
  and Guy L. Steele Jr.

  Hope this helps
  Cheers
  Naief
  BBTG


> Thanx.
> 
> 
>  ,--------------------------------------,     ____            ___  _______
>  | Alexey N. Dokuchaev, more commonly   |    / __/______ ___ / _ )/ __/ _ \
>  | known as DAN Fe                      |   / _// __/ -_) -_) _  |\ \/ // /
>  |                                      |  /_/ /_/  \__/\__/____/___/____/
>  | Novosibirsk State University         `-------- The Power to Serve --------,
>  | Scientific Study Center Computer Lab                                      |
>  |                                                                           |
>  | email: danfe@inet.ssc.nsu.ru     homepage: http://inet.ssc.nsu.ru/~danfe/ |
>  | ICQ UIN: 38934845                                                         |
>  `---------------------------------------------------------------------------'
> 
> A good conspiracy is unprovable.  I mean, if you can prove it, it means they
> screwed up somewhere along the line.
> 
> 					Jerry Fletcher from Conspiracy Theory
> 

-- 
-------------------------------------------------------
Naief BinTalal         |  naief@cyfari.com
-------------------------------------------------------
"A rock pile ceases to be a rock pile the moment a
 single man contemplates it, bearing within him the
 image of a cathedral" -- Antoine de Saint-Exupery
------------------------------------------------------- 


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?20000113102234.A45156>