Check the Arg Count

karl at haddock.UUCP karl at haddock.UUCP
Fri Jan 16 11:35:22 AEST 1987


[I've added comp.lang.c to the discussion.  --kwzh]
In article <5064 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
[Re the problem of type-checking on varargs functions]
>What is needed is a way of telling the compiler, `this routine takes
>arguments described by ...' that is general enough to cover printf, scanf,
>execl, and so forth, yet simple enough so that new ones can be introduced as
>necessary, and so that the syntax is not unduly cluttered.  The real problem
>is in conveying the `described by' part.  System V lint has /*PRINTFLIKE*/
>and /*SCANFLIKE*/ pragmas in its lint library, which takes care of printf and
>scanf and variants, but not execl.  Would adding /*REPEATING*/ suffice?  I
>cannot say.

Functions like execl(), which are variadic but not polymorphic, are the simple
case; adding /*REPEATING*/ and /*SENTINEL (char *)0*/ would be sufficient to
document these.*

Some functions switch on one arg to determine how to process the others.  (I
think these should be avoided in favor of separate functions when possible.)
These could be documented to lint as follows:
	/* SWITCHON 2 */
	int ioctl(int, TIOCNOTTY);
	int ioctl(int, TIOCGPGRP, int *);
	int ioctl(int, TIOCSPGRP, const int *);
	int ioctl(int, TIOCSTI, const char *);
However, this notation doesn't quite cover SysV open().

/*PRINTFLIKE*/, etc are a kludge; they require the syntax rules to be built
into the typechecker.  (The printf-like routine in adb, e.g., is excluded.)
To handle this in full generality would require something like an correctness-
proving language.  Fortunately, few variadic functions are of this type (and
the standard ones, as mentioned, are hard-coded).

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint
*Along with /*SENTINEL*/, there should be another notation for functions whose
arg count is explicitly passed as one of the arguments.  Neither of these
would be necessary if C supported nargs().



More information about the Comp.lang.c mailing list