This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C pre-DR#10: static main


This 10th pre-DR concludes the set 
<http://www.srcf.ucam.org/~jsm28/gcc/#drs> I currently have pending 
consideration at the next UK C Panel meeting (or a subsequent one if there 
is too much other business at the next meeting): I don't at present have 
further issues pending writing up for consideration, though more might 
always arise.

Pre-DR: static main
===================

C99 5.1.2.1.1#1 says:

       [#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[]) { /* ... */ }

       or  equivalent;9)  or  in  some other implementation-defined
       manner.

Being equivalent means that this function has external linkage.

1. May such an implementation-defined manner include a definition of
main as a function with internal linkage?

2. May a translation unit other than the one defining the function
main called at program startup define an object (in any case) or
function (if the answer to question 1 is "no" or the function is not
of such implementation-defined form) with internal linkage, also
called main, or is this undefined behavior?  For example, may a
translation unit contain the declaration

  static double main;

or

  static long main(double x) { return 0; }

?

3. C99 6.7.4#4 says:

       [#4]  In a hosted environment, the inline function specifier
       shall not appear in a declaration of main.

Does this constraint refer only to the function main called at program
startup, or to any identifier of that name?  That is, does

  static inline int main(void) { return 0; }

always violate this constraint?  (This question still applies even if
such a declaration yields undefined behavior.)

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
  http://www.srcf.ucam.org/~jsm28/gcc/#c90status - status of C90 for GCC 4.0
    jsm@polyomino.org.uk (personal mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]