From toddpw@cco.caltech.edu Fri Dec 11 04:33:57 1992 Received: from calvin.sfasu.edu by umaxc.weeg.uiowa.edu (5.61.jnf/920629) on Fri, 11 Dec 92 04:33:54 -0600 id AA28003 with SMTP Received: from punisher.caltech.edu (punisher.cco.caltech.edu) by calvin.sfasu.EDU with SMTP (5.59/25-eef) id AA15621; Fri, 11 Dec 92 04:28:49 CST Return-Path: Received: from sandman.caltech.edu (sandman.cco.caltech.edu) by punisher.caltech.edu (4.1/DEI:4.41) id AA18202; Fri, 11 Dec 92 02:26:41 PST From: toddpw@cco.caltech.edu (Todd P. Whitesel) Received: by sandman.caltech.edu (4.1/UGCS:4.41) id AA00402; Fri, 11 Dec 92 02:28:28 PST Message-Id: <9212111028.AA00402@sandman.caltech.edu> Subject: Re: '@' declaration in HyperC To: hyperc-l@calvin.sfasu.edu Date: Fri, 11 Dec 92 2:28:27 PST In-Reply-To: <00964E43.BB0F0EE0.18073@cip.physik.uni-stuttgart.de>; from "Wulf Hofbauer" at Dec 10, 92 6:45 pm X-Mailer: ELM [version 2.3 PL11] Status: R >This can be a major time (and frustration) saver. The alternatives were to use >pointers (produces only slightly less effective code, but requires >weird-looking type casting) or to use external assembly routines (function >calling overhead, must be linked). C evolution has made this (almost) part of the language now. ANSI C lets you define a constant pointer (i.e. you initialize it with an address and the compiler knows it will always hold that address); when you use the pointer, a good compiler will be able to substitute the address instead of explicitly storing the pointer somewhere -- this achieves exactly the same code as using "@" does, except that you do have the pointer dereferences all over your source. It's also a good idea to declare the pointer to a volatile object, so optimizers won't mess you up for doing hardware register type things with it. The resulting pointer declaration looks a bit weird but does exactly what you want, and relies on cleaner extensions to the language ("const" and "volatile" are used to advantage in other parts of the language as well). C++ has "references" which are a lot like "@" but are more general; you can create a reference almost anywhere and have it refer to practically any other object of the same type. If you declare a constant reference to a volatile object and initialize it with an appropriately typed number, it also does exactly what "@" does, but without the pointer semantics. Unfortunately, references in C++ are so general that they cause a lot of problems with other features of the language. But the cool thing about them is that they implement Pascal "var" parameters pretty cleanly. Todd Whitesel toddpw @ cco.caltech.edu