RE: [Dev-C++] BC++, gcc and Win98SE shell
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ya...> - 2002-02-24 16:49:02
|
> -----Original Message-----
> From: Ioannis Vranos [mailto:no...@ya...]
> Sent: Sunday, February 24, 2002 6:45 PM
> To: Dev-C++ (dev...@li...)
> Subject: RE: [Dev-C++] BC++, gcc and Win98SE shell
>
>
> Now something delicate. argc is *not* guaranteed to be one if
> you do not pass any argument. It is guaranteed that if you
> pass an argument then it will be non zero and argv[0] will be
> the name of the program itself. In few words, if you do not
> pass any name it is not guaranteed that argv[0] contains the
> name of the program. As the C++ standard says:
That is wrong. The correct is: If argc>0 then argv[0] is the name of the
program, e.t.c.. In few words before you use argv you must always check
if argc>0.
> "An implementation shall not predefine the main function.
> This function shall not be overloaded. It shall have a return
> type of type int, but otherwise its type is
> implementationdefined. All implementations shall allow both
> of the following definitions of main: int main() { /* ... */
> } and int main(int argc, char* argv[]) { /* ... */ } In the
> latter form argc shall be the number of arguments passed to
> the program from the environment in which the program is run.
> If argc is nonzero these arguments shall be supplied in
> argv[0] through argv[argc1] as pointers to the initial
> characters of nullterminated multibyte strings (NTMBSs)
> (17.3.2.1.3.2) and argv[0] shall be the pointer to the
> initial character of a NTMBS that represents the name used to
> invoke the program or "". The value of argc shall be
> nonnegative. The value of argv[argc] shall be 0. [Note: it is
> recommended that any further (optional) parameters be added
> after argv. ]".
>
>
>
> This is exactly the same for ANSI C89 and C99 too.
With the exception that in C it is int main(void) instead of int main().
Also C89 did not require any return value for main().
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.d2g.com
* Alternative URL: http://run.to/noicys
|