Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!amdcad!ames!sri-spam!rutgers!psuvax1!gondor.psu.edu!schwartz From: schwartz@gondor.psu.edu (Scott E. Schwartz) Newsgroups: comp.lang.c Subject: Re: Question on structures Message-ID: <3048@psuvax1.psu.edu> Date: Tue, 3-Nov-87 12:43:07 EST Article-I.D.: psuvax1.3048 Posted: Tue Nov 3 12:43:07 1987 Date-Received: Sat, 7-Nov-87 05:32:43 EST References: <1025@phoenix.Princeton.EDU> <2986@mit-vax.LCS.MIT.EDU> <5673@weitek.UUCP> Sender: netnews@psuvax1.psu.edu Reply-To: schwartz@gondor.psu.edu (Scott E. Schwartz) Organization: Penn State University, University Park, PA Lines: 34 In article <5673@weitek.UUCP> rober@weitek.UUCP (Don Rober) writes: >>A simple solution (sligthly inefficient). Rewrite >> with a.b.c begin >> d = 10 ; >> end >>as >> { >> struct *s = &a.b.c ; >> s->d = 10 ; >> } >A vastly superior solution in that there is nothing implicit happening. The >typical Pascal error is that it is never clear what 'd' is a reference to. Typical for who? Anyone framiliar with nested block structured languages should have no problem with this. Certainly "never" is too strong a qualifier. >(for example, declare a local variable by the name of 'd' - which one is >referenced?) 'd' refers to the field in the record. That's part of the scoping rules. Don't you ever have local variables whose names clash with names of global variables? (If not, I applaud you, but since C doesn't allow nested procedures the temptation is very much less.) > This C solution obviates the problem and is worth whatever the >cost may be. I disagree. The 'cost' is clarity and efficiency. I want both of these. I mean, why declare, initialise and use a thoroughly useless local variable when all you wanted was a (constant offset) field in a record anyway? -- Scott Schwartz schwartz@gondor.psu.edu