🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #4582

Re: Check the Arg Count

#4582
From: karl
Date: Fri, 16 Jan 1987 01:35
36 lines
2576 bytes
[I've added comp.lang.c to the discussion.  --kwzh]
In article <5064@mimsy.UUCP> chris@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@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().
Technical Details
Message-ID: <305@haddock.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!ima!haddock!karl
References: <1634@enea.UUCP> <594@mcgill-vision.UUCP> <1639@enea.UUCP> <5064@mimsy.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!ima!haddock!karl
From: karl@haddock.UUCP
Newsgroups: comp.lang.misc,comp.lang.c
Subject: Re: Check the Arg Count
Message-ID: <305@haddock.UUCP>
Date: Thu, 15-Jan-87 20:35:22 EST
Article-I.D.: haddock.305
Posted: Thu Jan 15 20:35:22 1987
Date-Received: Fri, 16-Jan-87 07:16:15 EST
References: <1634@enea.UUCP> <594@mcgill-vision.UUCP> <1639@enea.UUCP> <5064@mimsy.UUCP>
Reply-To: karl@haddock.ISC.COM.UUCP (Karl Heuer)
Followup-To: comp.lang.c
Organization: Interactive Systems, Boston
Lines: 36