This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Same code, same script, different results


On Thu, 23 Sep 2004, Mikael Åsberg wrote:

Hello, I am using the latest Cygwin with all packages updated (running
Windows XP Professional SP2) and I'm having a problem with a simple C++
program that uses the Win32 API to scan a directory (recursively or
non-recursively, depending on user input). The code is as follows:

[snip]
     if(strcmp(argv[2], "--non-recursive") == 0) {
        recursive = false;
        cout << "Will perform a non-recursive scan of directory "
             << argv[1] << "." << endl;
     } else {
        cerr << "Ignoring unknown option " << argv[2] << "." << endl;
     }
[snip]

Yours was by far not a minimal testcase. The above would have sufficed.


If I test this program with the following bash script:
#!/bin/bash
echo "Performing a scan without using recursion"
./directory_scanner.exe c:\\coding\\cygwin\\c++\\ --non-recursive

Does your bash script have DOS line endings? Try "d2u bashscript".


the output is:
Performing a scan without using recursion
Ignoring unknown option --non-recursive.
[Recursive listing snipped]

If I compile the exactly the same code under MSVC++ 7.1 and invoke the
executable it produces with the exactly the same script, the output is:
Performing a scan without using recursion
Will perform a non-recursive scan of directory c:\coding\cygwin\c++\.
[Non-recursive listing snipped]

What's going on here? Why doesn't strcmp() return 0 if compiled with g++
with the input given above?

Apparently MSVCRT's startup code considers \r to be whitespace, and Cygwin's doesn't. Use Unix line endings, or put the script on a text mount. Igor -- http://cs.nyu.edu/~pechtcha/ |\ _,,,---,,_ pechtcha@cs.nyu.edu ZZZzz /,`.-'`' -. ;-;;,_ igor@watson.ibm.com |,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski, Ph.D. '---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow!

"Happiness lies in being privileged to work hard for long hours in doing
whatever you think is worth doing."  -- Dr. Jubal Harshaw


Lol, you're right, Igor, that test case was far from minimal. Should've cut it down, of course. On the other hand, I often see people cutting away what they think is unrelated code or whatnot, when, in fact, they are cutting away the cause of their problems when posting questions.


Anyway, it's working as expected now. But to tell the truth I don't know exactly what the problem was. I tinkered some with the script, did a make clean ; make (again), and, voila, it works. I'm glad that it works, but it's a bit annoying not understanding what the problem and the rememdy was.

Thanks for on-list replies and private emails

/ Mikael

PS. I remember once having the cygwin mailing list in "usenet style format" in outlook express, but I can't for the life of me remember what I did. Anyone knows what I'm talking about? DS.



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]