Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.supernews.com!news.supernews.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 22 Oct 2012 18:47:04 -0500 From: Steve Thompson Newsgroups: comp.lang.c Subject: Re: Compatibility question Date: Mon, 22 Oct 2012 22:52:44 +0000 Organization: Friends of the Galactic Collective Message-ID: References: <0.a87a1c8a472d870b0466.20121022022701BST.87y5izxpne.fsf@bsb.me.uk> <0.d779297035d2edccd1b4.20121022173052BST.87ehkqbhab.fsf@bsb.me.uk> <2nYjPo.Krd.2aRbe@gmail.com> <0.5ef6d4d4944842791bc8.20121022210639BST.87pq4a9sq8.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit User-Agent: NN 6.4.3 Lines: 71 X-Trace: sv3-oeOUfzjQAumuqPJM8GXOPtkZZzb66D2Bmxnim5JJangAXiHN+TrzQy/r+WC4WAim1maMBIwxVLGtnGF!4wIkPi5avcZE22tY04HSv/NQg6Hh1zLwmfPlyXHYiSx28jDrqZuMuJXY3Zwjpg== X-Complaints-To: www.supernews.com/docs/abuse.html X-DMCA-Complaints-To: www.supernews.com/docs/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 4602 Xref: csiph.com comp.lang.c:27549 On Mon, Oct 22, 2012 at 09:06:39PM +0100, Ben Bacarisse wrote: > Steve Thompson writes: > > > On Mon, Oct 22, 2012 at 10:52:47AM -0700, Keith Thompson wrote: > >> Steve Thompson writes: > >> [...] > >> > No annoyance taken, although now that I think of it it does show an > >> > instance of overloaded semantics, which can be confusing. When I was > >> > less experienced with C, I was confused by the fact that variables > >> > defined as structures were not pointers: > >> > > >> > struct point { > >> > int x, y, z; > >> > }; > >> > > >> > struct point a; > >> > > >> > > >> > One cannot reference 'a' (as such) in an expression even though it is > >> > a pointer in the implementation because C allows one to use structures > >> > as arguments to a function. I'd never do that in my own code, but > >> > some people may like the fact that they can pass complex data > >> > structures around as if they were simple variables. I think it wastes > >> > resources, but of course that is less of an issue today than it was > >> > when C was first developed. > >> > >> I'm not sure what you mean when you say `a` "is a pointer in > >> the implementation", especially after you mention "the fact that > >> variables defined as structures were not pointers". > > > > Meaning that under the hood in the C compiler, 'a' is really a > > pointer. The logic of the compiler causes it to use the structure > > data as specified in the standard, but conceptually 'a' is still a > > pointer to the data in the specific structure identified by 'a'. I > > found it very confusing when I was learning C. > > I am not surprised. I would have found it totally baffling when I was > learning C. I find it baffling even now, having learnt C! > > Whatever goes on under the hood (and I'd dispute that 'a' is "really a > pointer") it's much easier to learn a language in its own terms, at > least as far as that's possible. Well, no. 'a' is never a pointer as such in the terms of the language syntax, but its treatment by the compiler internally is nominally equivalent to they way it handles a pointer, with the exception that the language grammar forbids its use in the program text as a pointer. In a simplistic sense, all variables are pointers to a segment of program data, modifiable or otherwise. In the real world, variable values may move around in and from RAM to CPU registers and back while being identified as a single consistent entity. This helps to illustrate the difference between a language and its implementation. > In C terms, 'a' names an object and 'a' is a (modifiable) lvalue > expression, just as if it had been declared to be an int. trying to > reconcile this with some model that says it's a pointer (when it isn't > one) is bound to be confusing. I was never happy with the term lvalue or rvalue. My brain wants to think in terms of pointers, variables, and values. Structures defined as automatic variables don't fit all that neatly in that classification. Regards, Steve Thompson -- GOTO's are like guns. Safety is entirely contingent on the user.