main() linkage

Rahul Dhesi dhesi%cirrusl at oliveb.ATC.olivetti.com
Tue Nov 28 12:18:57 AEST 1989


What is erroneous programming practice?

One overly simple definition is "programming practice that violates the
ANSI C standard".  Which is not a very useful definition when
considering code that was written before the ANSI C standard came into
being.

I have seen the usual use of printf to be considered an error waiting
to be fixed.  (I have even seen Ritchie as being quoted as saying
something like this.)  But if K&R defined the C programming language in
a certain way, and that definition required printf to be used in a
certain way, and if millions of lines of existing *correctly working
code* uses printf, thow can that usage possibly be erroneous?

On the other hand, existing code can stop working through no fault of
its own, if compilers are changed to no longer compile it correctly.
For example, if compiler writers suddenly begin to use a linkage
convention that varies from function to function, printf will no longer
work.  That does not mean that the original C code was erroneous.
Rather, it is the compiler that is no longer compiling C code the way
it used to be compiled.

So was it portable to declare main() to return void?  As always,
portability depends on your universe.  Within the universe of C
implementations that supported the language as defined by K&R, which
was roughly equivalent to the universe of existing C implementations,
it was always portable to declare main() to return anything you wanted,
provided you always existed by calling exit.  *That has not changed*.
What has changed is universe of existing C implementations, and it has
changed because the meaning of "C" has changed.

Rahul Dhesi <dhesi%cirrusl at oliveb.ATC.olivetti.com>
UUCP:  oliveb!cirrusl!dhesi



More information about the Comp.lang.c mailing list