programming challenge (silly)

Rick Schubert rns at se-sd.sandiego.ncr.com
Thu Mar 30 02:12:45 AEST 1989


In article <2417 at buengc.BU.EDU> bph at buengc.bu.edu (Blair P. Houghton) writes:
>In article <1866 at se-sd.sandiego.ncr.com> rns at se-sd.sandiego.NCR.COM (Rick Schubert(AEP)) writes:
>>I believe that
>>	argc == 0 && argv[0] == NULL
>>is intended for the case where the implementation has no access to
>>the command line (or there is no command line), whereas
>>	argc > 0 && argv[0] == ""
>>is intended for the case where the implementation has access to the command
>>line but not to the program name.

>I get it.  One is a null pointer, and the other is a pointer-to-a-null...
>				--Blair

In the interest of trying to keep my postings brief and to the point, I
may, at times, assume too much and leave out something that maybe should
have been said.  When I wrote:

>>	argc > 0 && argv[0] == ""
>>is intended for the case where the implementation has access to the command
>>line but not to the program name.

I meant to imply that not only
	argc > 0
but that, potentially
	argc > 1

That is, since the implementation has access to the command line but not to
the program name, the program may be invoked with arguments, which are
pointed to by argv[1], argv[2], ..., argv[argc-1].  As always,
	argv[argc] == NULL
so that, if argc == 0,
	argv[0] == NULL
Also, argv[i] (for 0 <= i < argc) points to a C string (i.e. is not NULL),
so that, if argc > 0, argv[0] cannot be NULL and must point to a string.
If the program name is not available, "" is probably the most reasonable
choice.

I hope this posting strikes a good balance between conciseness and verbosity.
Also, I hope that my mixing of C expressions and C/English is not too confusing
(I can't post in multiple fonts).

-- Rick Schubert (rns at se-sd.sandiego.NCR.COM)



More information about the Comp.lang.c mailing list