Variable argument lists.

00704a-Liber nevin1 at ihlpf.ATT.COM
Sat May 21 09:27:42 AEST 1988


In article <5451 at bloom-beacon.MIT.EDU> raeburn at athena.mit.edu (Ken Raeburn) writes:
>How about the average number of arguments passed to variadic
>functions?  They're the only ones that should need the information.

>Yes, I realize that includes *printf, some of the most-used functions.
>(And *scanf too, but who in their right mind uses those anyways? :->)
>And the work that they do quite likely far outways the cost of an
>extra argument, especially since that argument is going to be a
>constant known at compile-time.

Yes, but things like *printf() have to *interpret* the first argument to
find out all the necessary info on the rest of the variables (such as
type).  Also, someone might pass to *printf() n+1 parameters and change the
format string so that only n-k parameters get printed.

>I wouldn't mind a very slight extra cost for runtime code to catch
>that missing argument to printf when I goof up.

Unless this is caught at *compile* time, I have no need or want of this
check.  What normally happens when you give it too few
arguments?  It either prints funny results or it bombs with a memory error.
What happens if the check is put in?  Very likely, the program would just
die (same thing happens in Pascal with range errors; this is one of the
primary reasons that I dislike Pascal).  The programs I write need to be
able to recover from errors.  I want good, efficient code that does not pay
a penalty because some of the people who code in C don't do it correctly.
If I can get all my printf/scanf's correct, why should I pay a penalty??

>And for those who do insist on using *scanf, it's probably of greater
>importance.  While printf might by chance pick up some stack garbage
>or random stuff in data space, or could die by reaching outside the
>address space, scanf will probably cause trouble by overwriting the
>same information.

Are there any statistics on this kind of stuff?

As you have stated, *printf is used a lot.  For this reason alone, I want
it to be as fast as possible.
-- 
 _ __			NEVIN J. LIBER	..!ihnp4!ihlpf!nevin1	(312) 510-6194
' )  )				"The secret compartment of my ring I fill
 /  / _ , __o  ____		 with an Underdog super-energy pill."
/  (_</_\/ <__/ / <_	These are solely MY opinions, not AT&T's, blah blah blah



More information about the Comp.lang.c mailing list