Program startup

Previous Table of Contents "New C Standard" commentary

162 The function called at program startup is named main.

163 The implementation declares no prototype for this function.

164 It shall be defined with a return type of int and with no parameters:

        int main(void) { /* ... */ }

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

166 or equivalent;9)

167 or in some other implementation-defined manner.

168 If they are declared, the parameters to the main function shall obey the following constraints:

169 —  The value of argc shall be nonnegative.

170 —  argv[argc] shall be a null pointer.

171 —  If the value of argc is greater than zero, the array members argv[0] through argv[argc-1] inclusive shall contain pointers to strings, which are given implementation-defined values by the host environment prior to program startup.

172 The intent is to supply to the program information determined prior to program startup from elsewhere in the hosted environment.

173 If the host environment is not capable of supplying strings with letters in both uppercase and lowercase, the implementation shall ensure that the strings are received in lowercase.

174 —  If the value of argc is greater than zero, the string pointed to by argv[0] represents the program name;

175 argv[0][0] shall be the null character if the program name is not available from the host environment.

176 If the value of argc is greater than one, the strings pointed to by argv[1] through argv[argc-1] represent the program parameters.

177 —  The parameters argc and argv and the strings pointed to by the argv array shall be modifiable by the program, and retain their last-stored values between program startup and program termination.


Created at: 2008-01-30 02:39:39 The text from WG14/N1256 is copyright © ISO