Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Dec 2001 12:25:17 +0100 (CET)
From:      Harti Brandt <brandt@fokus.gmd.de>
To:        Erik Trulsson <ertr1013@student.uu.se>
Cc:        Mark Murray <mark@grondar.za>, 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:  <20011218121556.U414-100000@beagle.fokus.gmd.de>
In-Reply-To: <20011218111156.GB1464@student.uu.se>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 18 Dec 2001, Erik Trulsson wrote:

ET>On Tue, Dec 18, 2001 at 11:17:34AM +0100, Harti Brandt wrote:
ET>
ET>> ET>main should always return an int.
ET>>
ET>> This is not entirely true. In the text you provide below from the C99
ET>> draft you stripped the sentence the allows an hosted environment to define
ET>> whatever main() function it decides to define. Appendix K.3.2 lists the
ET>> implementation-defined behaviour for the environment:
ET>>
ET>> - An alternative manner in which the main function may be defined.
ET>>
ET>> But, this is just to be theoretically correct :-). Our environment defines
ET>> main() as returning int, so correct programs should declare and define
ET>> main() main as returning int. But, given that the compiler has no
ET>> knowledge about main() (the text below states, that the compiler does NOT
ET>> declare main()), it cannot give you an error.
ET>
ET>The text says that the compiler does not supply a prototype for main().
ET>Indeed it cannot do so, since there are *two* different forms for
ET>main(), both of which are legal.
ET>
ET>This does not mean that the compiler does not know anything about main().
ET>
ET>Note that the C standard does not really make a distinction between the
ET>C language itself and the standard library.  As far as the standard is
ET>concerned the standard library is part of the language and the compiler
ET>can have arbitrarily good knowledge about it.
ET>(For example, the compiler is allowed to check if the arguments to
ET>printf match the supplied format string and warn otherwise. Since
ET>printf is defined by the standard, can compiler knows how it should
ET>behave and is allowed to act on that knowledge.)

Well, the standard makes a distinction between the environment and the
language (compiler, library, ...) itself. As such, the exact form of
main() is part of the environment, not of the language. So using the wrong
main() should not cause the compiler to reject your code. It gives you an
implementation-defined behaviour when executing the program. Likewise
having extra knowledge about library functions doesn't give the compiler
the right to reject your program. It can, however, give you any number of
warnings it wants.

To come back to the subject: you agree, that the compiler does not supply
a prototype to main (having knowledge about main is not the same as
prototyping main()). So, if we use compiler options to give us a warning,
whenever a function is used/defined without a prototype and to turn
warnings into errors, every program, which does NOT prototype main()
should give us an error. So the right thing to do if we want those errors
is to prototype main().

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?20011218121556.U414-100000>