Article View: comp.std.c
Article #1999When is argc = 0 useful?
From: Roger House
Date: Fri, 16 Nov 1990 23:04
Date: Fri, 16 Nov 1990 23:04
27 lines
1695 bytes
1695 bytes
While specifying code for implementing a C runtime function which sets up argc and argv for main, a question arose as to when argc might be zero. In section 2.1.2.2.1 (Program Startup) of the ANSI C reference it says that argc must always be nonnegative and argv[argc] must be a null pointer. Thus, if argc = 0, then argv[argc] = null pointer. However, in the environment that I am working in, the program name is always known, so when there are no parameters to the program on the command line, argc = 1, argv[0] = progam name, and argv[1] = null. Thus, argc is never zero when main is called. The only situation I can think of in which argc might be zero is in an environment in which the program name is not known. Then, if there are no parameters on the command line, argc = 0 and argv[0] = null might be useful. But, on the other hand, the standard already takes care of the situation when the program name is not known. In this situation, if argc > 0 then argv[0][0] must be a null character. Thus, a portable program must treat the following two situations in the same way: 1) argc = 0 2) argc = 1 and argv[0][0] = 0 IMHO, it would be simpler and cleaner to simply require argc > 0 in all instances. Comments, anyone? Roger House
Technical Details
Message-ID:
<1990Nov16.230420.23923@everexn.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!elroy.jpl.nasa.gov!swrinde!ucsd!pacbell.com!pacbell!barn!everexn!rogerShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!elroy.jpl.nasa.gov!swrinde!ucsd!pacbell.com!pacbell!barn!everexn!roger From: roger@everexn.com (Roger House) Newsgroups: comp.std.c Subject: When is argc = 0 useful? Message-ID: <1990Nov16.230420.23923@everexn.com> Date: 16 Nov 90 23:04:20 GMT Distribution: na Organization: Everex Systems, Inc. Lines: 27