howard@metheus.UUCP (Howard A. Landman) (08/10/84)
How about using a well-understood English language convention to indicate optional arguments? Namely, the ellipsis, "...". For example: printf(char *, ...); fprintf(FILE *, char *, ...); sprintf(char *, char *, ...); Isn't this perfectly clear? I can't see any way that this would conflict with any other C keywords or usage. Is there something I'm missing? Howard A. Landman ogcvax!metheus!howard (until August 14th) "If I knew the way, I would take you home"
trt@rti-sel.UUCP (08/10/84)
None of the proposals I have seen would fix the 'execl' problem:
execl("/bin/date", "date", 0); /* should be (char *)0 */
FIX 1 (a varying number of arguments of specified type):
int execl(char * ...); /* no comma! (yup, obscure) */
to mean 0 or more arguments of type char *, whereas
int printf(char *, ...);
means a char * followed by 0 or more arguments of unknown type.
The correct specification for execl would really be:
int execl(char *, char * ...); /* execl has >= 1 argument */
I suppose one might have a strange function like:
int weird(int ..., float, ..., char *);
which means ... oh forget it. Pity the compiler writers.
FIX 2 (overloaded(?) declarations):
int execl(char *); int execl(char *, char *);
int execl(char *, char *, char *); ...
I prefer FIX 1 since it is more compact and covers all the varargs
programs I can think of. It would be reasonable to require
that the '...' must appear last (to simplify implementation).
Tom Truscotthenry@utzoo.UUCP (Henry Spencer) (08/12/84)
My understanding was that the ellipsis ("...") was among the ideas for
varargs syntax that the ANSI group looked at. I don't know why they
rejected this particular one, but they *did* consider it.
--
Henry Spencer @ U of Toronto Zoology
{allegra,ihnp4,linus,decvax}!utzoo!henryguy@rlgvax.UUCP (Guy Harris) (08/14/84)
Another person had also mentioned the use of an ellipsis to indicate a function
which takes a number (possibly zero) of "fixed" arguments, and a number
of "variable" arguments after it; i.e.,
int fprintf(FILE *, char *, ...);
This is how it's done in C++, according to the C++ Reference Manual.
Guy Harris
{seismo,ihnp4,allegra}!rlgvax!guy