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:45:29
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of gi...@li...
> Sent: Sunday, February 24, 2002 5:03 PM
> To: dev...@so...
> Subject: [Dev-C++] BC++, gcc and Win98SE shell
>
>
> Hello list,
>
> here is one, funny, thing of which I have no explanation:
>
> consider the following program:
>
> /* echo.c */
> #include <stdio.h>
>
> int
> main(int argc, char **argv)
> {
> while (--argc)
This decreases the number reported, which has no effect.
> printf("%s ", *++argv);
Here you printf *after* you increment, that is you lose the first
string.
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:
"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.
>
> return 0;
> }
>
> I compiled it using:
> GNU gcc 2.95 shipped with Dev-C++ (gcc -o echo_g.exe echo.c)
> BC++ 5.5 of thge "Borland free command line tools" (bcc32 -eecho_b.exe
> echo.c).
>
> Then I've "touched" the files "foo.c" and "bar.c" and tried
> the following:
>
> command output
> echo_g *.c bar.c foo.c
> echo_b *.c *.c
>
> All of this on Win98SE.
> Is there somebody that can tell what is going on?
> Is this bug(?) common to the shell of other Windows systems too?
I do not understand what you did.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.d2g.com
* Alternative URL: http://run.to/noicys
|