Date: Tue, 18 Dec 2001 10:36:32 +0100 From: Erik Trulsson <ertr1013@student.uu.se> 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: <20011218093631.GA1096@student.uu.se> In-Reply-To: <200112180848.fBI8mvO00685@grimreaper.grondar.org> References: <XFMail.011216160443.jhb@FreeBSD.org> <200112180848.fBI8mvO00685@grimreaper.grondar.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <stdio.h> 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 <stdio.h> > > 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 <float.h>, <iso646.h>, <limits.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, and <stdint.h> -- <Insert your favourite quote here.> Erik Trulsson ertr1013@student.uu.se 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?20011218093631.GA1096>