Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!apple!oliveb!amiga!jimm From: jimm@amiga.UUCP (Jim Mackraz) Newsgroups: comp.sys.amiga Subject: Re: Struggling through the "C" Message-ID: <3748@amiga.UUCP> Date: 13 Apr 89 23:19:17 GMT References: <2570@ssc-vax.UUCP> <231@nlgvax.UUCP> Reply-To: jimm@cloyd.UUCP (Jim Mackraz) Organization: Commodore-Amiga Inc, Los Gatos CA Lines: 54 )>In article <97113@sun.Eng.Sun.COM>, Chuck McManis writes: )>>char *a; /* This is a pointer to a string */ )>>char a[80]; /* this is a pointer to a string with 80 bytes allocated */ )In article <2570@ssc-vax.UUCP> dmg@ssc-vax.UUCP (David Geary) writes: )> No! char a[80] is not a pointer at all. It is an array... In article <231@nlgvax.UUCP> hans@nlgvax.UUCP (Hans Zuidam) writes: )Please check your K&R before responding: ) ) K&R 7.1, pg. 185: ) An identifier is a primary expression, provided it has been ) suitably declared as discussed below. If the type of the identifier ) is "array of ...", then the value of the identifier-expression is a ) pointer to the first object in the array, and the type of the ) expression is "pointer to ...". )So: ) 'char *a' is *identical* to 'char a[80]' *except* for the ) fact that in the second definition 'a' is a *constant* ) pointer. That is: you cannot assign a value to 'a'. A fine reading of K&R, but if you declare char a[80]; in one file, and extern char *a; in another, your code won't run, regardless of how you interpret K&R. For the former, the symbol 'a' resolves to the address of 80 bytes of storage, for the latter, 'a' resolves to an address which may contain the address of some storage. They differ by one level of indirection. As a convenience, the syntax rules for using arrays and pointers are interchangable. In the case of function parameters, the parameter is a pointer in either case (the address of storage, either the constant or the *contents* of a pointer) is pushed on the stack in either case.) When evaluating the argument, the stack location *contains* the address of some storage. So, K&R stress that the declarations themselves (not just the usage syntax) are interchangable. But, what they do NOT stress, is that in GENERAL (i.e., for globals) the declarations are NOT interchangable, and no compiler will help you, no debugger will help you, and you will be dead. Only lint will help you, or the benefit of being killed in a previous life ... jimm -- Jim Mackraz, I and I Computing "He's hidden now, but you can see {cbmvax,well,oliveb}!amiga!jimm The holes where he breathes." - Shriekback Opinions are my own. Comments are not to be taken as Commodore official policy.