argc/argv

Warren Young tangent@cyberport.com
Sun Jan 31 23:52:00 GMT 1999


At 05:24 PM 1/14/99 +0800, you wrote:
>Hi! Evidently gcc treats argc/argv quite differently from
>Turbo C when * appears in any argvs. It always tries to
>replace this argv with as many as possible matching files.

[snip]

>i know nothing about any standard or coding conventions
>about this, but could any of you tell me which is more
>standard or conventional?

Actually, it's not gcc setting up argv that way, but the C startup code
that ships with Cygwin's C library (libc).  This libc is trying to be
Unix-like in the absence of a Unix shell.  On a true Unix-like operating
system, the shell (sh, csh, bash, etc.) expands wildcards before running
the program.  But since you can't count on this under Win32, libc
apparently takes over this task.

It's curious, though, that when you run your test program under Cygwin's
bash like this:

	$ test "t*"

the t* isn't expanded.  This is normally the Right Thing, since double
quotes tells the shell not to expand wildcards, but the wildcarded argument
should be expanded by libc as it is when you run it from cmd.exe.  I
suspect that bash passes the quotes to the program literally, so that the C
startup routines will see them and not to expand the wildcard.

As for which behavior is "correct", the Cygwin behavior is correct if
you're trying to create a Unix-like environment, which they are.  Plus,
since wildcard conventions are substantially the same under Unix and DOS
(Unix is more or less a simple superset), it doesn't hurt compatibility to
do this.

Incidentally, you can make Turbo C-compiled programs expand their arguments
by linking in a special object file that comes with the compiler.  I can't
remember what it's called, but you can find info about it by searching the
techinfo archive at www.inprise.com.  Of course, it only expands the
DOS-standard * and ? wildcards (not the full regular expression suite
offered by Unix shells) but that's usually enough.  When it's not, run your
TC-compiled program under Cygwin's bash, which will do a full expansion for
you.

Good luck,

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".



More information about the Cygwin mailing list