prototype my function, please

Stephen Clamage steve at taumet.COM
Sat Jun 2 02:15:45 AEST 1990


In article <1990May31.135230.242 at druid.uucp> darcy at druid.UUCP (D'Arcy J.M. Cain) writes:
>So can anyone summarize the ANSI compilers (or K&R1 compilers for that
>matter) for which decalaring main to return void causes a problem?

The ANSI standard says that in a hosted environment, a strictly
conforming program will define main as
	int main() { /* ... */ }
or
	int main(int argc, char *argv[]) { /* ... */ }
(The names argc and argv are not required by the standard, but you
have to call the args something if they are declared.)

A compiler may allow anything it wishes in addition, but programs
depending on other defintions being legal may not be portable.

As to "lying to the compiler" when you terminate via exit(), the
standard says:
	"A return from the initial call to the _main_ function function
	is equivalent to calling the _exit_ function with the value returned
	by the _main_ function as its argument."
So the compiler is not allowed to be upset when exit() does not return.

I don't see any value in making lists of which detailed extensions are
supported by which particular compilers.  Compilers often accept (and
reject) different extensions in different releases.  Such a list
becomes quickly unmanageable.  Write for maximum portability and isolate
unavoidable dependencies for easy fixing.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list