Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!clyde!cbosgd!osu-eddie!osu-cgrg!spencer From: spencer@osu-cgrg.UUCP (Steve Spencer) Newsgroups: comp.lang.c Subject: Re: Writing readable code Message-ID: <854@osu-cgrg.UUCP> Date: Sat, 4-Jul-87 09:12:03 EDT Article-I.D.: osu-cgrg.854 Posted: Sat Jul 4 09:12:03 1987 Date-Received: Sat, 4-Jul-87 20:29:00 EDT References: <8286@ut-sally.UUCP> <7001@alice.UUCP> <364@sol.ARPA> <1213@carthage.swatsun.UUCP> Organization: Computer Graphics Research Group, Columbus OH Lines: 48 Summary: It's not ALWAYS that easy... In article <1213@carthage.swatsun.UUCP>, rice@swatsun (Dan Rice) writes: > > center = s2->o; > > if I plan to use s2->o several times? Thanks for any help. > -- > - Dan Rice, Swarthmore College, Swarthmore PA 19081 > ...!sun!liberty!swatsun!rice > ...!seismo!bpa!swatsun!rice Yes, I would (and have) used something like what you describe when I have to use the current values in s2->o many times in a function (example: if s2->o was the intersection point of a ray with a sphere in a ray-tracing program and the function in which I was working was a shader. :-)) BUT...... Some C compilers will let you get away with center = s2->o; (i.e.: structure assignments) But some won't. Your best bet for non-flakiness is: center.x = (s2->o).x; center.y = (s2->o).y; center.z = (s2->o).z; Sure, it's three statements instead of one, but (1) You are certain that all three values were assigned correctly. (2) If you had to access (as you speculated) s2->o.x multiple times, you are saving yourself cycles in the long run. Hope I helped... steve -- ...I'm growing older but not up... - Jimmy Buffett Stephen Spencer, Graduate Student The Computer Graphics Research Group The Ohio State University 1501 Neil Avenue, Columbus OH 43210 {decvax,ucbvax}!cbosg!osu-cgrg!spencer (uucp)