Date: Tue, 18 Dec 2001 10:35:02 +0100 (CET) From: Harti Brandt <brandt@fokus.gmd.de> To: Mark Murray <mark@grondar.za> Cc: John Baldwin <jhb@FreeBSD.ORG>, "David O'Brien" <obrien@FreeBSD.ORG>, <cvs-all@FreeBSD.ORG>, <cvs-committers@FreeBSD.ORG>, Luigi Rizzo <rizzo@aciri.org>, Garance A Drosihn <drosih@rpi.edu> Subject: Re: Are prototypes for main() illegal by any standard ? (was Re: Message-ID: <20011218102348.W5601-100000@beagle.fokus.gmd.de> In-Reply-To: <200112180848.fBI8mvO00685@grimreaper.grondar.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 18 Dec 2001, Mark Murray wrote:
MM>> > This is comming up due to a bug in a single compiler. We have fixed that
MM>> > compiler. AFAIK the other two compilers we use at all today -- TenDRA
MM>> > and Compaq's compiler does not have this bug. So why change all this
MM>> > code when we fixed things at the source of the problem?
MM>>
MM>> Agreed. Requesting prototypes for main is the compiler bug, not hiding the
MM>> warning for main.
MM>
MM>This I do not understand. :-)
MM>
MM>AFAIK, this is perfectly legal C:
MM>
MM>/* begin */
MM>void printf(char *, ...)
MM>
MM>void main(void)
MM>{
MM> printf("Hello world");
MM>}
MM>/* end */
MM>
MM>And it should compile warning-free and run without error. Agreed
MM>that the style sucks, but it is _legal_ - and any compiler's prior
MM>assumed knowledge about main is plain wrong - it is a linker thing
MM>to use ``main'' as an entry point, and nobody else's damn business
MM>what it is after that! (argc and argv are likewise conventions that
MM>are less useful in an embedded environment with no shell (ya, ya I
MM>know about execv :)).
MM>
MM>Now if anyone can show official standards showing me that I'm
MM>wrong here, I'll shut up and back off. :-)
Clause 1 of section 5.1.2.2.1 of my ISO-C draft states that in a hosted
(not freestanding environment):
"The function called at program startup is named main. The implementation
declares no prototype for this function. It shall be defined with a return
type of int and with no parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any
names may be used, as they are local to the function in which they are
declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent; or in some other implementation-defined manner."
Up to now I was under the impression, that the compiler should have
an implicit prototype for main(). But the second sentence above states
that it does not. As I understand the wording, Mark is right.
harti
--
harti brandt, http://www.fokus.gmd.de/research/cc/cats/employees/hartmut.brandt/private
brandt@fokus.fhg.de
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011218102348.W5601-100000>
