From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d17561d7e5eba62c X-Google-Attributes: gid103376,public From: Rex Reges Subject: Re: An alternative to Unchecked Conversion Date: 1999/12/18 Message-ID: <385AD199.D1428985@Boeing.com>#1/1 X-Deja-AN: 562150673 Content-Transfer-Encoding: 7bit Sender: nntp@news.boeing.com (Boeing NNTP News Access) X-Nntp-Posting-Host: crux.ds.boeing.com References: <38596575_4@news1.prserv.net> <3859701a@rsl2.rslnet.net> Content-Type: text/plain; charset=us-ascii Organization: The Boeing Company Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-12-18T00:00:00+00:00 List-Id: Brian Orpin wrote: > > Well the Tartan Ada (83) compiler we are using doesn't allow us to use > address mapping as it requires all address statements to be static. > > With SYSTEM; > Use SYSTEM; > > Procedure TEST Is > Type TEST_TYPE Is New INTEGER; > For TEST_TYPE'Size Use 32; > > X : TEST_TYPE; > Y : TEST_TYPE; > For X Use At Y'Address; > > Begin > > X := 1; > > End TEST; > > 9| Y : TEST_TYPE; > test.ada:10:1: > 10| For X Use At Y'Address; > ^1 > *** 1 Error 3271: A static expression is expected here (RM83 4.9) > This is a problem with Ada83, but it is a little more subtle. I think the problem you have here is that you are trying to do this overlay (the Jovial term) on two items on the stack. If you put your declarations in a package, it should work. However, I had assumed the intent of an address rep clause was to support device drivers and DMA. Unchecked conversion works better than overlays in many cases since it can detect things that an address overlay can't (like mod boundaries, packed bits, packed items smaller than a storage unit, etc.). Also, unchecked conversion can do more efficient memory moves by switching to double register loads (64 bit loads) as soon as a 64 bit boundary is hit. Also, to support overlays, the compiler writers had to add the Pragma Volatile so that "tautology" errors didn't occur (checking the same variable over and over when it can't change as far as the compiler knows. Some compilers would just optimize out the second test on a variable that it didn't know was overlayed. The static expression requirement is a problem when writing a device driver since the device's location is located at a physical address and the expression required is a logical address. One can call a system routine to map the physical to logical, but then the address is not static. I assume most compilers extended Ada83 with the ability to call To_Logical_Address( Physical_Address : in System.Address ) return System.Address. For Ada95, it doesn't seem to be a problem to have a run-time value for the address rep clause. The "aliased" specification on a declaration tells the compiler that you expect the variable to be volatile. We create MMAP regions at run-time and overlay a data structure on these memory regions for sharing between processes. As far as the compiler can tell, data magically appears out of nowhere in these structures (mostly queues). However, several gurus here now claim that unchecked conversion should never be used. Either they use overlays or they call the C library routine "memmov" instead. Their claim is that "memmov" is faster and more portable than unchecked conversion. I disagree. It seems to me that overlaying stack items and block memory moves are poor programming styles, but I'm not a guru. -------------- Rex Reges "De gustibus non est disputandum."