RE: [Dev-C++] BC++, gcc and Win98SE shell
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Benjamin W. <ben...@ho...> - 2002-02-25 13:28:02
|
<html><div style='background-color:'><DIV>
<P>Good morning,</P>
<P>I guess I am just restating what the other two gentlemen already have...but to me, it sounds like more of a discrepancy within the two compilers rather than something wrong with the Win98 Shell.</P>
<P>Exactly what that discrepancy is, I do not know. As for which is performing correctly...I'm not sure that is a valid statement or question...it really depends on what the programmer's intention is...and I would say that they are both performing correctly, perhaps just not as expected since they give different results.</P>
<P>Anyway, just my two cents worth. Have a great day!</P></DIV>
<DIV></DIV>
<DIV><FONT face="Geneva, Arial, Sans-serif" size=2>Benjamin Wheeless</FONT></DIV>
<DIV></DIV>
<DIV><FONT face="Geneva, Arial, Sans-serif" size=2><STRONG>Network Systems - Delta Airlines, Inc.</STRONG></FONT></DIV>
<DIV></DIV>
<DIV><FONT face=Arial size=2><STRONG>Atlanta, GA - USA 30320</STRONG></FONT></DIV>
<DIV></DIV>
<DIV><FONT face=Arial size=2><STRONG>==============================</STRONG></FONT></DIV>
<DIV> </DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>----Original Message Follows----
<DIV></DIV>From: gi...@li...
<DIV></DIV>To: dev...@so...
<DIV></DIV>Subject: RE: [Dev-C++] BC++, gcc and Win98SE shell
<DIV></DIV>Date: Sun, 24 Feb 2002 23:37:51 +0100
<DIV></DIV>
<DIV></DIV>Sorry for my previous post, it was not very clear.
<DIV></DIV>
<DIV></DIV>Let me try again.
<DIV></DIV>
<DIV></DIV>The test program is, this time, a little different:
<DIV></DIV>
<DIV></DIV>/* echo.c */
<DIV></DIV>#include <STDIO.H>
<DIV></DIV>int main(int argc, char *argv[])
<DIV></DIV>{
<DIV></DIV>while (--argc > 0)
<DIV></DIV>printf("%s%s", *++argv, (argc > 1) ? " ": "");
<DIV></DIV>printf("\n");
<DIV></DIV>return 0;
<DIV></DIV>}
<DIV></DIV>
<DIV></DIV>IMHO the above is more or less equivalent to the program I posted before
<DIV></DIV>but I changed in the hope that Ioannis won't yell at me this time :-)
<DIV></DIV>
<DIV></DIV>Anyway the program is not the point, it is just a mean to show that:
<DIV></DIV>when I use a program compiled by gcc, it seems that the shell expands
<DIV></DIV>wildcards before invoking the program (as it should always be), instead
<DIV></DIV>when I compile the same program using BC++, the shell does not expand the
<DIV></DIV>wildcards.
<DIV></DIV>
<DIV></DIV>To prove it, what I did was:
<DIV></DIV>1. create a directory named c:\temp
<DIV></DIV>2. used the program "touch" (a Borland tool) to create: c:\temp\foo.c and
<DIV></DIV>c:\temp\bar.c
<DIV></DIV>3. switched to the directory c:\temp
<DIV></DIV>4. issued the command: echo_g *.c
<DIV></DIV>
<DIV></DIV>The ouput of the command was:
<DIV></DIV>
<DIV></DIV>bar.c foo.c
<DIV></DIV>
<DIV></DIV>This means that the shell expanded "*.c" into "bar.c foo.c", the two
<DIV></DIV>arguments were then echoed by the program "echo_g" (where the "_g" means
<DIV></DIV>compiled using gcc).
<DIV></DIV>
<DIV></DIV>Instead if I use the version of echo compiled by BC++ (named "echo_b.exe"),
<DIV></DIV>that is, when step #4 becomes:
<DIV></DIV>
<DIV></DIV>4. issued the command: echo_b *.c
<DIV></DIV>
<DIV></DIV>The output is:
<DIV></DIV>
<DIV></DIV>*.c
<DIV></DIV>
<DIV></DIV>This means that the shell did not expand "*.c". Or, if you prefer, I have
<DIV></DIV>the same ANSI C89 program give two different outputs, according to which
<DIV></DIV>compiler was used to build the executable. I have no explanation for this,
<DIV></DIV>other than there is some bug in the shell.
<DIV></DIV>
<DIV></DIV>My questions are
<DIV></DIV>1. Why is the Windows shell (or command.com, if you prefer) acting
<DIV></DIV>differently?
<DIV></DIV>2. Is this happening on my Win98SE or is it happening on other versions of
<DIV></DIV>Windows too?
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>At 18:45 24/02/02 +0200, Ioannis Vranos wrote:
<DIV></DIV>> > -----Original Message-----
<DIV></DIV>> > From: dev...@li...
<DIV></DIV>> > [mailto:dev...@li...] On Behalf
<DIV></DIV>> > Of gi...@li...
<DIV></DIV>> > Sent: Sunday, February 24, 2002 5:03 PM
<DIV></DIV>> > To: dev...@so...
<DIV></DIV>> > Subject: [Dev-C++] BC++, gcc and Win98SE shell
<DIV></DIV>> >
<DIV></DIV>> >
<DIV></DIV>> > Hello list,
<DIV></DIV>> >
<DIV></DIV>> > here is one, funny, thing of which I have no explanation:
<DIV></DIV>> >
<DIV></DIV>> > consider the following program:
<DIV></DIV>> >
<DIV></DIV>> > /* echo.c */
<DIV></DIV>> > #include <STDIO.H>
<DIV></DIV>> >
<DIV></DIV>> > int
<DIV></DIV>> > main(int argc, char **argv)
<DIV></DIV>> > {
<DIV></DIV>> > while (--argc)
<DIV></DIV>>
<DIV></DIV>> This decreases the number reported, which has no effect.
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>> > printf("%s ", *++argv);
<DIV></DIV>>
<DIV></DIV>>Here you printf *after* you increment, that is you lose the first
<DIV></DIV>>string.
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>Now something delicate. argc is *not* guaranteed to be one if you do
<DIV></DIV>>not
<DIV></DIV>>pass any argument. It is guaranteed that if you pass an argument
<DIV></DIV>>then it
<DIV></DIV>>will be non zero and argv[0] will be the name of the program itself.
<DIV></DIV>>In
<DIV></DIV>>few words, if you do not pass any name it is not guaranteed that
<DIV></DIV>>argv[0]
<DIV></DIV>>contains the name of the program. As the C++ standard says:
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>"An implementation shall not predefine the main function. This
<DIV></DIV>>function
<DIV></DIV>>shall not be overloaded. It shall
<DIV></DIV>>have a return type of type int, but otherwise its type is
<DIV></DIV>>implementationdefined.
<DIV></DIV>>All implementations
<DIV></DIV>>shall allow both of the following definitions of main:
<DIV></DIV>>int main() { /* ... */ }
<DIV></DIV>>and
<DIV></DIV>>int main(int argc, char* argv[]) { /* ... */ }
<DIV></DIV>>In the latter form argc shall be the number of arguments passed to
<DIV></DIV>>the
<DIV></DIV>>program from the environment in
<DIV></DIV>>which the program is run. If argc is nonzero these arguments shall
<DIV></DIV>>be
<DIV></DIV>>supplied in argv[0] through
<DIV></DIV>>argv[argc1]
<DIV></DIV>>as pointers to the initial characters of nullterminated
<DIV></DIV>>multibyte strings (NTMBSs)
<DIV></DIV>>(17.3.2.1.3.2) and argv[0] shall be the pointer to the initial
<DIV></DIV>>character
<DIV></DIV>>of a NTMBS that represents the
<DIV></DIV>>name used to invoke the program or "". The value of argc shall be
<DIV></DIV>>nonnegative. The value of
<DIV></DIV>>argv[argc] shall be 0. [Note: it is recommended that any further
<DIV></DIV>>(optional) parameters be added after
<DIV></DIV>>argv. ]".
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>This is exactly the same for ANSI C89 and C99 too.
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>> >
<DIV></DIV>> > return 0;
<DIV></DIV>> > }
<DIV></DIV>> >
<DIV></DIV>> > I compiled it using:
<DIV></DIV>> > GNU gcc 2.95 shipped with Dev-C++ (gcc -o echo_g.exe echo.c)
<DIV></DIV>> > BC++ 5.5 of thge "Borland free command line tools" (bcc32
<DIV></DIV>>-eecho_b.exe
<DIV></DIV>> > echo.c).
<DIV></DIV>> >
<DIV></DIV>> > Then I've "touched" the files "foo.c" and "bar.c" and tried
<DIV></DIV>> > the following:
<DIV></DIV>> >
<DIV></DIV>> > command output
<DIV></DIV>> > echo_g *.c bar.c foo.c
<DIV></DIV>> > echo_b *.c *.c
<DIV></DIV>> >
<DIV></DIV>> > All of this on Win98SE.
<DIV></DIV>> > Is there somebody that can tell what is going on?
<DIV></DIV>> > Is this bug(?) common to the shell of other Windows systems too?
<DIV></DIV>>
<DIV></DIV>>I do not understand what you did.
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>Ioannis
<DIV></DIV>>
<DIV></DIV>>* Ioannis Vranos
<DIV></DIV>>* Programming pages: http://www.noicys.d2g.com
<DIV></DIV>>* Alternative URL: http://run.to/noicys
<DIV></DIV>>
<DIV></DIV>
<DIV></DIV>--
<DIV></DIV>gisan
<DIV></DIV>gi...@li...
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>_______________________________________________
<DIV></DIV>Dev-cpp-users mailing list
<DIV></DIV>Dev...@li...
<DIV></DIV>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
<DIV></DIV></div><br clear=all><hr>Send and receive Hotmail on your mobile device: <a href='http://go.msn.com/bql/hmtag2_etl_EN.asp'>Click Here</a><br></html>
|