Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site sdcsla.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!houxm!houxz!vax135!cornell!uw-beaver!tektronix!hplabs!sdcrdcf!sdcsvax!sdcsla!pilotti From: pilotti@sdcsla.UUCP (Keith Pilotti) Newsgroups: net.lang.c Subject: Re: K&R App A, par. 8 & 8.2, on Declarat - (nf) Message-ID: <619@sdcsla.UUCP> Date: Wed, 1-Aug-84 02:15:57 EDT Article-I.D.: sdcsla.619 Posted: Wed Aug 1 02:15:57 1984 Date-Received: Sat, 28-Jul-84 09:44:32 EDT Expires: Wed, 8-Aug-84 03:00:00 EDT References: <8@ism780b.UUCP> <166@tellab2.UUCP> Reply-To: pilotti@sdcsla.UUCP (Keith Pilotti) Organization: U.C. San Diego, Cognitive Science Lab Lines: 30 In article <166@tellab2.UUCP> thoth@tellab2.UUCP (Marcus Hall) writes: >>int a = 2; >>main() { >> a = 1; >> >> x(); >>} >>x() { >> printf("%d\n", a); >>} >> >>will print "2" if "a = 1" is a declaration, >>"1" if it is an assignment (current, expected, behavior). > >No, the reference to 'a' in x() is to the global 'a'. The 'a' that is inside > main() can only be referenced inside main or by passing the address to another > function. > >marcus >..!ihnp4!tellab1!tellab2!thoth There IS NO 'a' inside main(), that is the point of the original article. The 'a = 1' is an assignment to the GLOBAL 'a', and the program prints '1'. (Tested on C compilers on both VAX (4.2BSD) and Sun Workstation (1.1)) ___________________________________________________________ KEITH F PILOTTI -- UC SanDiego Cognitive Science Laboratory ...{philabs,ucbvax}!sdcsvax!sdcsla!pilotti (UUCP) pilotti@NPRDC (ARPA)