Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!necntc!ima!haddock!karl From: karl@haddock.ISC.COM (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Accessing argc & argv from a function Message-ID: <1207@haddock.ISC.COM> Date: Mon, 21-Sep-87 16:39:19 EDT Article-I.D.: haddock.1207 Posted: Mon Sep 21 16:39:19 1987 Date-Received: Wed, 23-Sep-87 00:43:22 EDT References: <22@flmis06.ATT.COM> <28700015@ccvaxa> <853@mcgill-vision.UUCP> <185@hobbes.UUCP> <884@mcgill-vision.UUCP> <222@hobbes.UUCP> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 27 In article <222@hobbes.UUCP> root@hobbes.UUCP (John Plocher) writes: >If one wanted to make the arguments avaliable w/o going thru main() then I >agree that you could just make crt0 put them into static locations, BUT would >anyone use that feature? Would you? No, you (and I) know about argc/v and >how to use them. The beginning C pgmr would soon learn the "right" way also, >and use *it*. Yes, I would. (And I'm not a beginner, by any strech of the imagination.) If argv[0] were available in a static location, I would have subroutines that use it in error messages. For example, an ideal implementation of "perror" should always print the program name, optionally print an additional string (often the name of a file that couldn't be opened), and the strerror text. Perhaps an existing analogy would help. Most UNIX implementations pass a third argument, envp, to main. I never use it. Most of the time that I need this value, I'm in a subroutine other than main, so I use the static cell (environ) that's also provided. Even if I do want to access it from main, I prefer to use environ rather than envp, just for consistency. (For similar reasons, I prefer "exit" to "return" in main.) Lest you misunderstand -- I see no reason to make all of argv global. I believe argv[1] through argv[argc-1] are, as their name implies, arguments to main. I think putting the program name into the argv[] array was a mistake; it should have been a global in the first place, and the real arguments should have been numbered starting at zero. But it's too late to change that now. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint