Stephen Mayes said:
Correct me if I am mistaken.
The C standard guarantees that in a C hosted environment we can
define main as:
int main( int argc, char *argv[] ).
Yes, without the full stop, and with braces to indicate a
function definition.
I always assume that 'argc' is the number of pointers in the array
'argv' and that the pointers in 'argv' point to null-terminated
strings, and that those strings represent a command line.
Is this always the case?
If argc is not zero, then the array members argv[1] through to
argv[argc - 1] point to null-terminated strings with an
implementation-defined value, representing the "program parameters".
On computers where there is such a thing as a command line, and the
program is invoked in such a way as to supply a command line, then
any command line arguments are usually supplied in this way.
Some operating systems do not have the concept of command line
arguments, whereas some other operating systems have multiple
ways to invoke a program, some of which allow specifying program
parameters and some of which do not.
C99 5.1.2.2.1 Program Startup, paragraph 2
If they are declared, the parameters to the main function shall
obey the following constraints:
- The value of argc shall be nonnegative.
- argv[argc] shall be a null pointer.
- 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. The intent is
to supply to the program information determined prior to
program startup from elsewhere in the hosted environment. 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.
- If the value of argc is greater than zero, the string pointed
to by argv[0] represents the program name; argv[0][0] shall be
the null character if the program name is not available from
the host environment. If the value of argc is greater than one,
the strings pointed to by argv[1] through argv[argc-1]
represent the program parameters.
- 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.