cdecl and pascal keywords
Karl Heuer
karl at ima.isc.com
Sat Jan 5 05:32:43 AEST 1991
In article <2847 at cirrusl.UUCP> dhesi%cirrusl at oliveb.ATC.olivetti.com (Rahul Dhesi) writes:
>In theory, there is no need for a "pascal" keyword if you're using ANSI C...
Unless the compiler is going to do cross-file analysis (e.g. with a fixup at
link time), it would have to assume that all non-variadic functions are
pascal-like. (It's irrelevant whether or not a prototype is in scope, since
int main(void) { return f(1); }
and
extern int f(int);
int main(void) { return f(1); }
are equivalent programs, irregardful of whether f() is defined with or without
a prototype in its own source file.)
But if the compiler treats non-variadic functions and variadic functions
differently, it would break the common (but non-ANSI) usage
/* no <stdio.h>! */
int main() { printf("hello, world\n"); return 0; }
because it doesn't know that printf() is variadic.
Conclusion: an implementation must do one of the following:
[0] Be prepared to distinguish variadic from non-variadic functions at link
time.
[1] Treat all functions as caller-pop (unless otherwise indicated by a
nonstandard keyword like "__pascal").
[2] Treat all non-variadic functions as callee-pop, and break old programs
such as the above. (A warning "no prototype for printf()" helps here.)
[3] Recognize "printf" and friends as reserved words even when <stdio.h> is
missing.
Karl W. Z. Heuer (karl at ima.isc.com or uunet!ima!karl), The Walking Lint
More information about the Comp.lang.c
mailing list