Topic: Is argv[0] Specified to Contain the Filename of the Executable on All Platforms?
Author: James Kanze <kanze@gabi-soft.de>
Date: Sat, 17 Feb 2001 14:53:57 GMT Raw View
Ron Natalie <ron@spamcop.net> writes:
|> sirwillard@my-deja.com wrote:
|> > In article <961j5u$e9v$1@solaris.cc.vt.edu>,
|> > At first glance the answer is yes, but if you read closely the
|> > answer is no. It may be an empty string.
|> Even if a non-empty argv[0] is provided, the standard doesn't
|> require it to be the path to the executable. It says the "name used
|> to invoke the program" which isn't (and has never been on any system
|> I've used) the full file path to the executable file.
>From a pratical point of view, under Unix (and I think under Windows as
well), argv[ 0 ] contains whatever the invoking program wanted it to
contain. It's a convention that the shells put the name the program was
invoked by there, but there is nothing to enforce it, and there are
special cases where it expressedly doesn't. (xterm, for example,
prepends a - character if it was invoked with the -ls option.)
I don't think that this is fully conforming, strictly speaking. Which
means that you cannot have a fully conforming C or C++ implementation
under Unix (and probably not under Windows).
--
James Kanze mailto:kanze@gabi-soft.de
Conseils en informatique orient e objet/
Beratung in objektorientierter Datenverarbeitung
Ziegelh ttenweg 17a, 60598 Frankfurt, Germany Tel. +49(069)63198627
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: comeau@panix.com (Greg Comeau)
Date: Sat, 17 Feb 2001 19:31:49 GMT Raw View
In article <86r90x5rhz.fsf@alex.gabi-soft.de>,
James Kanze <kanze@gabi-soft.de> wrote:
>Ron Natalie <ron@spamcop.net> writes:
>|>sirwillard@my-deja.com wrote:
>|>> In article <961j5u$e9v$1@solaris.cc.vt.edu>,
>|>> At first glance the answer is yes, but if you read closely the
>|>> answer is no. It may be an empty string.
>|>Even if a non-empty argv[0] is provided, the standard doesn't
>|>require it to be the path to the executable. It says the "name used
>|>to invoke the program" which isn't (and has never been on any system
>|>I've used) the full file path to the executable file.
>
>>From a pratical point of view, under Unix (and I think under Windows as
>well), argv[ 0 ] contains whatever the invoking program wanted it to
>contain. It's a convention that the shells put the name the program was
>invoked by there, but there is nothing to enforce it, and there are
>special cases where it expressedly doesn't. (xterm, for example,
>prepends a - character if it was invoked with the -ls option.)
>
>I don't think that this is fully conforming, strictly speaking. Which
>means that you cannot have a fully conforming C or C++ implementation
>under Unix (and probably not under Windows).
As I recall this for Standard C and Standard C++, the words are
loose in enough in each to accomodate this being conforming,
under all definitions of the word. IOWs, I think the standards
accept the practical point of view you discuss.
--
Greg Comeau Comeau C/C++ 4.2.44 "so close"
ONLINE COMPILER ==> http://www.comeaucomputing.com/tryitout
4.2.45 during February! NEW ONLINE: Try out our C99 mode!
comeau@comeaucomputing.com http://www.comeaucomputing.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: "Gillmer J. Derge" <spam@gillmerderge.com>
Date: Sat, 17 Feb 2001 19:31:34 GMT Raw View
"James Kanze" <kanze@gabi-soft.de> wrote in message
news:86r90x5rhz.fsf@alex.gabi-soft.de...
> I don't think that this is fully conforming, strictly speaking. Which
> means that you cannot have a fully conforming C or C++ implementation
> under Unix (and probably not under Windows).
I think that depends on your interpretation of the word "represents." The
sections of the Standard that were quoted previously say that the string in
argv[0] "represents the name used to invoke the program."
You seem to be taking that to mean "*is* the name used to invoke the
program." I think that's one reasonable interpretation, but it's not the
only one. To me it means that argv[0] "corresponds in some symbolic or
conceptual way to the name used to invoke the program," but it doesn't
necessarily need to be equal to the name.
As an example, "Dad" represents my father, but it isn't his name. :-)
-----
Gillmer J. Derge
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: James Kanze <kanze@gabi-soft.de>
Date: Mon, 19 Feb 2001 22:01:55 GMT Raw View
"Gillmer J. Derge" <spam@gillmerderge.com> writes:
|> "James Kanze" <kanze@gabi-soft.de> wrote in message
|> news:86r90x5rhz.fsf@alex.gabi-soft.de...
|> > I don't think that this is fully conforming, strictly speaking. Which
|> > means that you cannot have a fully conforming C or C++ implementation
|> > under Unix (and probably not under Windows).
|> I think that depends on your interpretation of the word
|> "represents." The sections of the Standard that were quoted
|> previously say that the string in argv[0] "represents the name used
|> to invoke the program."
|> You seem to be taking that to mean "*is* the name used to invoke the
|> program." I think that's one reasonable interpretation, but it's
|> not the only one. To me it means that argv[0] "corresponds in some
|> symbolic or conceptual way to the name used to invoke the program,"
|> but it doesn't necessarily need to be equal to the name.
|> As an example, "Dad" represents my father, but it isn't his
|> name. :-)
But how much liberty would that really give us. On at least one
occasion, I passed a totally arbitrary value in argv[0], with a few
characters that you wouldn't normally find in the name of a program; the
goal, or part of the goal at least, was to prevent a user from
accidentally invoking the program (which required some special set up,
and would only work if invoked from another program).
--
James Kanze mailto:kanze@gabi-soft.de
Conseils en informatique orient e objet/
Beratung in objektorientierter Datenverarbeitung
Ziegelh ttenweg 17a, 60598 Frankfurt, Germany Tel. +49(069)63198627
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: gennaro_prota@my-deja.com
Date: Sat, 10 Feb 2001 11:42:26 GMT Raw View
Clause 3.6 (Start and termination) specifies the following requirements:
- In freestanding implementations, there may not even be a main ( 3.6.1)
- [the main function] shall have a return type of type int, but
otherwise its type is implementation-defined.
- All implementations shall allow both of the following definitions of
main:
int main() { /* ... */ }
and
int main(int argc, char* argv[]) { /* ... */ }
[NOTE: but you cannot declare both forms: the main function cannot be
overloaded! :-) ]
- 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
[argc-1] as pointers to the initial characters of null-terminated
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.
Therefore: provided that there is a main function and that you use the
second form, argv[0] MAY be a pointer to an empty string or, if
argc==0, a null pointer.
Gennaro Prota.
Sent via Deja.com
http://www.deja.com/
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: "Jackson Yee" <jacksonyee@yahoo.com>
Date: Sat, 10 Feb 2001 15:15:14 GMT Raw View
Thanks for all of the quick answers, guys!
Regards,
Jackson Yee
http://jacksonyee.welcome.to/
E-mails for help will be ignored unless I had asked for them. Please post
to the group.
"Ron Natalie" <ron@spamcop.net> wrote in message
news:3A8455C6.6E7DC311@spamcop.net...
>
>
> Jackson Yee wrote:
> >
> > Sorry for asking this question, but I don't have an up-to-date version
of
> > the standard at the moment. What I'm looking for is whether argv[0] can
be
> > counted on to contain the filename of the program on all platforms such
as
> > Windows, Unix, and embedded systems, or if it is implementation-defined
> > whether the filename is there or not.
> >
> Nope, the standard just says that it's the name used to invoke the
program.
> It's not necessarily a complete path. It's not on UNIX where really
argv[0]
> is just what the caller passed to exec. The shell usually gives what the
> user typed so you don't get the full path. Can't vouch for windows, but I
> think it's the same (it is the command issued prior to the search).
>
> In UNIX there is no good way to find the path to the executable.
> In WINDOWS you can call SearchPath or other functions to determine this.
>
> ---
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
> [ Note that the FAQ URL has changed! Please update your bookmarks. ]
>
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: "Jackson Yee" <jacksonyee@yahoo.com>
Date: Fri, 9 Feb 2001 20:19:18 GMT Raw View
Sorry for asking this question, but I don't have an up-to-date version of
the standard at the moment. What I'm looking for is whether argv[0] can be
counted on to contain the filename of the program on all platforms such as
Windows, Unix, and embedded systems, or if it is implementation-defined
whether the filename is there or not.
--
Regards,
Jackson Yee
http://jacksonyee.welcome.to/
E-mails for help will be ignored unless I had asked for them. Please post
to the group.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: sirwillard@my-deja.com
Date: Fri, 9 Feb 2001 23:02:04 GMT Raw View
In article <961j5u$e9v$1@solaris.cc.vt.edu>,
"Jackson Yee" <jacksonyee@yahoo.com> wrote:
> Sorry for asking this question, but I don't have an up-to-date
version of
> the standard at the moment. What I'm looking for is whether argv[0]
can be
> counted on to contain the filename of the program on all platforms
such as
> Windows, Unix, and embedded systems, or if it is implementation-
defined
> whether the filename is there or not.
3.6.1/2
"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[argc-1] as pointers to the initial characters of null-terminated
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. ]"
At first glance the answer is yes, but if you read closely the answer
is no. It may be an empty string.
--
William E. Kempf
Software Engineer, MS Windows Programmer
Sent via Deja.com
http://www.deja.com/
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: brahms@mindspring.com (Stan Brown)
Date: Fri, 9 Feb 2001 23:45:40 GMT Raw View
Quoth Jackson Yee <jacksonyee@yahoo.com> in comp.std.c++:
>What I'm looking for is whether argv[0] can be
>counted on to contain the filename of the program on all platforms
No. Subclause 3.6.1, paragraph 2, says in part:
'If argc is nonzero these arguments shall be supplied in argv[0]
through argv[argc-1] as pointers to the initial characters of null-
terminated 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.'
So an implementation is allowed to have argc be 0, or to have argc
be positive and argv[0] point at a "" string.
--
Stan Brown, Oak Road Systems, Cortland County, New York, USA
http://oakroadsystems.com
C++ FAQ Lite: http://www.parashift.com/c++-faq-lite/
the C++ standard: http://webstore.ansi.org/
reserved C++ identifiers: http://oakroadsystems.com/tech/cppredef.htm
more FAQs: http://oakroadsystems.com/tech/faqget.htm
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]