[comp.sys.sgi] varargs and -prototype

srp@babar.mmwb.ucsf.edu (Scott R. Presnell) (05/10/91)

Hi,
	I am working on a program that uses varargs.  At the same time, but
for other reasons, I would like to use the IRIX -prototypes argument to
cc(1).  Is there a "correct" way to specify a prototype for a function that
uses varargs (and have it work with -prototypes)?  So far, I am having
trouble doing this.  

	Moreover, if I'm making some sort of basic mistake here, let me
know (like I need to *ask* for this on USENET...)  I'm just trying to ease
myself into ANSI C.

	Thanks for any help.

	- Scott

--
Scott Presnell				        +1 (415) 476-9890
Pharm. Chem., S-926				Internet: srp@cgl.ucsf.edu
University of California			UUCP: ...ucbvax!ucsfcgl!srp
San Francisco, CA. 94143-0446			Bitnet: srp@ucsfcgl.bitnet

micah@flobb4.csd.sgi.com (Micah Altman) (05/11/91)

In <srp.673809276@babar.mmwb.ucsf.edu> srp@babar.mmwb.ucsf.edu (Scott R. Presnell) writes:

>	I am working on a program that uses varargs.  At the same time, but
>for other reasons, I would like to use the IRIX -prototypes argument to
>cc(1).  Is there a "correct" way to specify a prototype for a function that
>uses varargs (and have it work with -prototypes)?  So far, I am having

For variable argument length argument lists in ANSI, you should be 
using the stdarg package, not the varargs package. The prototype form for a 
variable length list is to use an ellipsis "..." after the first argument:

	type function-name(first_arg_type,...)

 
The first argument type is mandatory, I think.

So for example, the declaration for printf would be:
	
	int printf(char* fmt,...);

For more information, check the man page on stdarg(5) and look in the
Ansi C version of the Kernighan and Ritchie book, "The C Programming
Language"




--
	"Entia non sunt multiplicanda sine necessitate." - William of Ockham
	Micah Altman, "Computational Juggler"	   	   micah@csd.sgi.com
	Phone (415) 335-1866				   FAX (415) 965-2309
	Disclaimer: 	Everything in this document is a lie.