Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!munnari!natmlab!basser!elecvax!cameron From: cameron@elecvax.eecs.unsw.oz (Cameron Simpson) Newsgroups: comp.unix.wizards Subject: Re: have I found a bug in K&R? Message-ID: <3802@elecvax.eecs.unsw.oz> Date: Fri, 16-Oct-87 05:12:51 EDT Article-I.D.: elecvax.3802 Posted: Fri Oct 16 05:12:51 1987 Date-Received: Sun, 18-Oct-87 09:51:34 EDT References: <18668@amdcad.AMD.COM> <517@hubcap.UUCP> <321@laticorp.UUCP> <7608@steinmetz.steinmetz.UUCP> Organization: EE and CS, Uni of NSW, Sydney, Australia Lines: 35 Summary: char s[], *t; /* t is an lvalue, s is not */ In article <18668@amdcad.AMD.COM> tim@amdcad.AMD.COM (Tim Olson) writes: >In article <7608@steinmetz.steinmetz.UUCP> dawn!stpeters@steinmetz.UUCP (Dick St.Peters) writes: >| In article <321@laticorp.UUCP> sarah@laticorp.UUCP (Sarah Groves Hobart) writes: >| >Remember that the following declarations are equivalent: >| >char s[]; >| >char *s; >| Actually, they're not. [ explaination deleted ] >Actually, you are both right. There are two places where a declaration >of an array with no size (and no initializer) are legal: 1) as a formal >parameter, and 2) as an external array declaration, where the array is >defined elsewhere. >As a formal parameter, char s[] and char *s are equivalent -- the >compiler coerces the former into the later. In that case you *can* >change s. As an external array declartion, the two are not equivalent. > -- Tim Olson > Advanced Micro Devices > (tim@amdcad.amd.com) I've been following this for a while. In all this discussion I have not once seen a word which crops up several times in K&R, namely `lvalue'. An lvalue is something which may occur on the left-hand side of an assignment statement. If I say char s[]; /* a character array of unspecified size */ char *t; /* a pointer to a character */ then I may say `t++;' or `t = s;' or `t = &s[2];' and so on. I may not say `s++;' or `s = t;'. This applies whether they are declared as formal parameters or as external array declarations. I often declare functions like fn(a,b) char *a; char b[]; in order to *prevent* myself from changing b during the function. It eliminates some coding errors by making the compiler do some extra checking for me. - Cameron Simpson, Uni of NSW, Australia