Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mimsy!umd5!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: Writing readable code Message-ID: <6058@brl-smoke.ARPA> Date: Sun, 5-Jul-87 16:00:01 EDT Article-I.D.: brl-smok.6058 Posted: Sun Jul 5 16:00:01 1987 Date-Received: Sun, 5-Jul-87 22:42:33 EDT References: <8286@ut-sally.UUCP> <7001@alice.UUCP> <364@sol.ARPA> <1158@copper.TEK.COM> <1213@carthage.swatsun.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB)) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 23 In article <1213@carthage.swatsun.UUCP> rice@swatsun (Dan Rice) writes: >sphere s1, *s2; >Now, say I refer to s1.o.x and s2->o.y. Does the compiler convert this into >a simple address reference at compile time, or is work performed at runtime? It of course depends on the implementation, but usually s1.o.x will become a direct memory reference while s2->o.y will of necessity (because s2 is variable) turn into a single-level indexed reference (the ->o and .y will usually be folded into a single offset). >Should I define >vector center; >center = s2->o; >if I plan to use s2->o several times? That depends on what you plan to do with it. The above causes a block move of the contents of the vector structure, whereas direct use of s2->o will not necessarily cause much data motion or even much additional overhead. In most cases you needn't allocate temporaries like this just for the sake of "efficiency". In case of bottleneck code, the best approach is to try each proposed efficiency hack individually to see if it makes a difference. Usually it won't, so you're better off keeping the code as intelligible as possible.