gwyn%brl-vld@sri-unix.UUCP (12/08/83)
From: Doug Gwyn (VLD/VMB) <gwyn@brl-vld> There is no mystery about argc[argv] = 0; pre-7th Edition PDP-11 UNIX exec marked the end of the arguments with a 16-bit constant -1 and newer UNIXes mark the end of the argument list with a (char *)0. The run-time start-off looks for this terminator to determine argc to pass to main(). The above code merely patches a 6th Edition image so that *argv++ can be easily used to pick up arguments and test for the last argument. (Not recommended.)
edhall%rand-unix@sri-unix.UUCP (12/08/83)
Take a look on page 210 of K & R. `...despite its asymmetric appearance, subscripting is a commutative operation.' Since E1[E2] == *(E1+E2), it follows that E1[E2] == E2[E1] !!! So argc[argv] is quite OK, though unconventional. -Ed Hall edhall@rand-unix (ARPA) decvax!randvax!edhall (UUCP)
ron%brl-vgr@sri-unix.UUCP (12/08/83)
From: Ron Natalie <ron@brl-vgr> Now wait... argc[argv] doesn't even sound legal to me. argc is usually an int while argv is char**. -Ron
jab@uokvax.UUCP (12/15/83)
#R:sri-arpa:-1443800:uokvax:6100002:000:451 uokvax!jab Dec 13 12:26:00 1983 In reference to the "argc[argv]" question/exercise: I just tried it with the Berkeley compiler (yet another PCC, so I'll make the [possibly invalid] assumption that other PCCs do this) and it does work. Given the correspondence "e1[e2] = *(e1 + e2) = *(e2 + e1) = e2[e1]" makes sense, in a way. I still think that it's awfully scruffy, but in C, a lot of programs are written making use of such [little-known] facts. Ugg. Jeff Bowles Lisle, IL