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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,227757d168eaa8a5 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!newshub.sdsu.edu!elnk-nf2-pas!elnk-pas-nf1!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread3.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: A question re meaning/use of the "for ... use ..." References: <41b3291e$0$44072$5fc3050@dreader2.news.tiscali.nl> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Sun, 05 Dec 2004 16:52:55 GMT NNTP-Posting-Host: 63.190.73.125 X-Complaints-To: abuse@earthlink.net X-Trace: newsread3.news.pas.earthlink.net 1102265575 63.190.73.125 (Sun, 05 Dec 2004 08:52:55 PST) NNTP-Posting-Date: Sun, 05 Dec 2004 08:52:55 PST Xref: g2news1.google.com comp.lang.ada:6779 Date: 2004-12-05T16:52:55+00:00 List-Id: Stephen Leake wrote: > There is no standard attribute that returns the internal > representation specified by the enumeration representation clause. > However, GNAT provides the non-standard 'Enum_Rep for this purpose. I have no problem with 'Pos returning the abstract position number, but do think something like GNAT's 'Enum_Rep should be standard, along with a conversion the other way, equivalent to 'Val ('Enum_Val?). For the OP, an enum rep is often used for interfacing to H/W, along with what is known as "change of representation". Consider a memory-mapped sensor. The application may interface to it via a package: package Sensor_IF is type Raw_Sensor_Value is (Not_Ready, Empty, Normal, Full, Overflow); subtype Sensor_Value is Raw_Sensor_Value range Empty .. Overflow; Hardware_Failure : exception; function Read return Sensor_Value; end Sensor_IF; The H/W memory location uses 4 bits, with the following interpretation: 2#0000# = Not ready 2#0001# = Empty 2#0010# = Normal 2#0100# = Full 2#1000# = Overflow So the implementation of the package might contain something like: package body Sensor_IF is type HW_Value is new Raw_Sensor_Value; for HW_Value use (Not_Ready => 2#0000#, Empty => 2#0001#, Normal => 2#0010#, Full => 2#0100#, Overflow => 2#1000#); Register_Address : constant System.Address := ...; -- This is a pedagogical example and ignores many of the complexities -- of real systems of this type, which have to deal with values like -- 2#0101# and MSBs that have to be masked off. Often readings have -- to be triggered by writing to a control register, and there are -- timing issues ... Register : HW_Value; for Register'Address use Register_Address; pragma Volatile (Register); function Read return Sensor_Value is Max_Tries : constant := ...; Result : HW_Value; begin -- Read Try : for I in 1 .. Max_Tries loop Result := Register; if Result /= Not_Ready then return Sensor_Value (Result); end if; end loop Try; raise Hardware_Failure; end Read; end Sensor_IF; -- Jeff Carter "We burst our pimples at you." Monty Python & the Holy Grail 16