Use of " ? : " in format param to printf

David Sherman dave at lsuc.uucp
Fri Jan 27 12:27:15 AEST 1989


In article <8801 at alice.UUCP>, ark at alice.UUCP (Andrew Koenig) writes:
> >     printf(count == 0 ? " ---- " : " %4.0lf ", sum / count);
> 
> > Does it matter if there are unused arguments to printf?
> 
> It's OK to have unused arguments in printf, but they'll be
> evaluated whether they're used or not.  Thus in this example
> if count is 0, the likely result is a divide by zero error.

Well, you could always signal(SIGFPE, SIG_IGN) before this.
Kind of kludgey, but I think it would get around that problem
as long as you're running UNIX...

David Sherman
-- 
Moderator, mail.yiddish
{ uunet!attcan  att  pyramid!utai  utzoo } !lsuc!dave



More information about the Comp.lang.c mailing list