From -4723604438259478647
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,2ec33dfd7f6145e8
X-Google-Attributes: gidf78e5,public
X-Google-Thread: fc772,f8b38cec4251c9a8
X-Google-Attributes: gidfc772,public
From: Stephen.Clamage@Eng.Sun.COM (Steve Clamage)
Subject: Re: main()???
Date: 1997/04/02
Message-ID: <199704012254.OAA14410@taumet.eng.sun.com>#1/1
X-Deja-AN: 230182384
References: <fjh-970401-054215@cs.mu.oz.au>
X-Original-Date: Tue, 1 Apr 1997 14:54:40 -0800
Organization: -
X-Auth: PGPMoose V1.1 PGP comp.std.c++
Newsgroups: comp.std.c++,comp.lang.c++.moderated
Originator: austern@isolde.mti.sgi.com


In article 054215@cs.mu.oz.au, fjh@mundook.cs.mu.OZ.AU (Fergus Henderson) writes:
>Stephen.Clamage@Eng.Sun.COM (Steve Clamage) writes:
>
>>Here is the relevent part of the draft standard (3.6.1 "Main function"):
>>
>>"The function main shall not be called from within a program. The linkage
>>(3.5) of main is implementation-defined. A program that takes the address
>>of main, or declares it inline or static is ill-formed."
>>
>>The "shall not" and "ill-formed" phrases means a diagnostic message is
>>required for any violation. (A compiler is allowed to accept the code
>>anyway, but normally you get an error message and no runnable program.)
>>A C++ compiler that accepts a call to main without complaint is not
>>conforming.
>
>The "ill-formed" phrase does mean that a diagnostic message is
>required for any violation, but the "shall not" phrase can mean
>either that a diagnostic is required, or that violation results
>in undefined behaviour, depending on exactly how the requirement
>is stated. ...
>
>With regard to the case in question, the requirement that Steve Clamage
>quoted, "the function main shall not be called from within a program"
>seems to me to be a requirement on the execution of a program, not on
>its form, and so no diagnostic is required.  (In contrast, if there
>requirement were "a program shall not contain a call to the function
>main", then it would be a requirement on the form, and so a diagnostic
>would be required -- but that is not the case.)
>
>>Calling main or taking its address was even disallowed by the ARM.
>
>Yes, but the ARM just says that "the function main may not be called
>from within a program", ...

The draft standard started out as the ARM with the commentary omitted
(literally: the troff source of the ARM was used for the original draft).
Wording of sections was modified as deficiencies were discovered. This
is a phrase that has survived unchanged so far.

It should have always been understood that in C++ it is an error
requiring a diagnostic to attempt to call main or take its address.
I guess no one noticed before that the words of the draft when taken
literally do not say that. (For example, the popular Plum Hall C++
Validation Suite has always had a test for calling or taking the
address of main in its "should not compile" section.)

I've submitted a request to clarify the wording in the draft. 

---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]



