Passing Arguments In C

Steve Summit scs at athena.mit.edu
Tue Sep 20 15:19:34 AEST 1988


In article <2232 at ssc-vax.UUCP> dmg at ssc-vax.UUCP (David Geary) writes:
>I teach an Advanced C class, and am showing my students how to write variadic
>functions.  I want to make sure that what I'm telling them is correct, and 
>also want to prepared to answer the questions in the above paragraph.  

As several people have pointed out, with incongruous reservations,
the right ways to write a variadic function are with varargs and
stdarg.  I'd like to:

  1. remove the reservations -- these are the only right ways to do it

  2. encourage you not to get your students too involved in what's
     going on "under the covers," even after your largely correct
     suppositions have been corrected by several previous articles.

There is a widespread conception that C can only be understood in
the context of the machine code being generated underneath.
Understanding that code is indeed fascinating, but exploring it
and writing programs which make use of it usually leads to
unwarranted further confusion.

Too often impressionable new students of the C language "learn"
the unintended lesson that all C programs are arcane masterpieces
of obfuscation which depend for their operation and understanding
on specific details of the underlying hardware.  There are "Intro
to C programming" books, intended for beginners, which are filled
with program upon machine-dependent program for finding out how
the particular implementation works.  If you're interested in
writing clean, portable code, you don't need or want to know this
stuff.  But if all of the example programs you see while learning
are obscure, those are the kinds of programs you will write.

                                            Steve Summit
                                            scs at adam.pika.mit.edu

P.S. I'm sure that the heresy in this article will get flamed by
     all of the obfuscation fans out there, and I'd list and
     rebut all of the counterarguments I'm sure I'll get, but
     it's late and I want to keep this article short, so I guess
     I'll have to deal with them as they come.



More information about the Comp.lang.c mailing list