Newsgroups: comp.windows.ms
Path: utzoo!utgpu!news-server.csri.toronto.edu!helios.physics.utoronto.ca!alchemy.chem.utoronto.ca!mroussel
From: mroussel@alchemy.chem.utoronto.ca (Marc Roussel)
Subject: Re: PATH for Windows applications
Message-ID: <1991Jun18.161154.28800@alchemy.chem.utoronto.ca>
Organization: Department of Chemistry, University of Toronto
References: <10816@plains.NoDak.edu> <465@dosbears>
Date: Tue, 18 Jun 1991 16:11:54 GMT

In article <10816@plains.NoDak.edu> coffman@plains.NoDak.edu (Clark Coffman)
writes:
>>  You know, that would work, but I've always wondered why professional
>>programmers don't use argv[0] to find the path! I'm what my friends call
>>a sportsman programmer in C and I use argv[0] to find where my programs
>>have been started up (so they can find their configuration files).

     I'm surprised that no one else has yet mentioned the main reason
not to use argv[0] to get the path: it isn't portable.  If your program
will never run on anything but DOS, then maybe it's a good idea.  (For
all I know there are lots of other reasons why it's not even a good idea
in DOS.)  On the other hand, at least under Unix, argv[0] isn't guaranteed to
return anything but the name the program was called under from the command
line.  It could include the path too, but it doesn't have to; argv[0]
just returns whatever the user typed.  If the user typed `foo -r bar`,
(and foo was in the PATH) argv[0] just gives 'foo'.  Given this
behaviour, it strikes that relying on argv[0] to return anything
sensible is a bad habit to get into.

				Marc R. Roussel
                                mroussel@alchemy.chem.utoronto.ca
