From owner-cvs-all Tue Dec 18 1:36:59 2001 Delivered-To: cvs-all@freebsd.org Received: from mailf.telia.com (mailf.telia.com [194.22.194.25]) by hub.freebsd.org (Postfix) with ESMTP id 2CB4837B421 for ; Tue, 18 Dec 2001 01:36:37 -0800 (PST) Received: from d1o913.telia.com (d1o913.telia.com [195.252.44.241]) by mailf.telia.com (8.11.6/8.11.6) with ESMTP id fBI9aYG25016 for ; Tue, 18 Dec 2001 10:36:34 +0100 (CET) Received: from ertr1013.student.uu.se (h185n2fls20o913.telia.com [212.181.163.185]) by d1o913.telia.com (8.8.8/8.8.8) with SMTP id KAA02594 for ; Tue, 18 Dec 2001 10:36:33 +0100 (CET) Received: (qmail 1116 invoked by uid 1001); 18 Dec 2001 09:36:32 -0000 Date: Tue, 18 Dec 2001 10:36:32 +0100 From: Erik Trulsson To: Mark Murray Cc: John Baldwin , "David O'Brien" , cvs-all@FreeBSD.org, cvs-committers@FreeBSD.org, Luigi Rizzo , Garance A Drosihn Subject: Re: Are prototypes for main() illegal by any standard ? (was Re: Message-ID: <20011218093631.GA1096@student.uu.se> Mail-Followup-To: Mark Murray , John Baldwin , David O'Brien , cvs-all@FreeBSD.org, cvs-committers@FreeBSD.org, Luigi Rizzo , Garance A Drosihn References: <200112180848.fBI8mvO00685@grimreaper.grondar.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200112180848.fBI8mvO00685@grimreaper.grondar.org> User-Agent: Mutt/1.3.24i Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Tue, Dec 18, 2001 at 10:48:56AM +0200, Mark Murray wrote: > > > This is comming up due to a bug in a single compiler. We have fixed that > > > compiler. AFAIK the other two compilers we use at all today -- TenDRA > > > and Compaq's compiler does not have this bug. So why change all this > > > code when we fixed things at the source of the problem? > > > > Agreed. Requesting prototypes for main is the compiler bug, not hiding the > > warning for main. > > This I do not understand. :-) > > AFAIK, this is perfectly legal C: Not quite. > > /* begin */ > void printf(char *, ...) Since you did not #include I guess you get away with this. (Most library functions are not reserved unless the relevant header is included.) > > void main(void) main should always return an int. > { > printf("Hello world"); > } > /* end */ You haven't defined the 'printf' anywhere. If you want to use the standard printf function you need to include > > And it should compile warning-free and run without error. Agreed No it should not. > that the style sucks, but it is _legal_ - and any compiler's prior > assumed knowledge about main is plain wrong - it is a linker thing > to use ``main'' as an entry point, and nobody else's damn business > what it is after that! (argc and argv are likewise conventions that > are less useful in an embedded environment with no shell (ya, ya I > know about execv :)). > > Now if anyone can show official standards showing me that I'm > wrong here, I'll shut up and back off. :-) The C standard does not make a distinction between compiler and linker, nor should it. A compiler is allowed to have a lot of knowledge about the standard functions. For a hosted environment it has the following to say about main: (From a draft for the C99 standard) 5.1.2.2.1 Program startup [#1] 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[]) { /* ... */ } For a freestanding environment (which can be useful for embedded stuff) you don't have any requirements on main(). OTOH about 95% of the standard library is not guaranteed to be available either. The only header files which may be included in a strictly program for a freestanding implementation are , , , , , , and -- Erik Trulsson ertr1013@student.uu.se To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message