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!news3.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!nntp.megapath.net!news.megapath.net.POSTED!not-for-mail NNTP-Posting-Date: Wed, 08 Dec 2004 13:48:44 -0600 From: "Randy Brukardt" Newsgroups: comp.lang.ada References: <41b3291e$0$44072$5fc3050@dreader2.news.tiscali.nl> Subject: Re: A question re meaning/use of the "for ... use ..." Date: Wed, 8 Dec 2004 13:50:02 -0600 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 Message-ID: NNTP-Posting-Host: 64.32.209.38 X-Trace: sv3-r1sg7ukMmTlYaRW2UXtIj41CIJUlDqclaoM3givPeF4D+iqVWXiexQJAseJr8chHzUwcym/SybNFLJy!zAAi5GN8qjdXITY3Ce0gO/k3k53Em8XGfhTmYj9Zusjdez3ZePXkJjvzQfb79G5eOu1BpcLXFvpF X-Complaints-To: abuse@megapath.net X-DMCA-Complaints-To: abuse@megapath.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.20 Xref: g2news1.google.com comp.lang.ada:6851 Date: 2004-12-08T13:50:02-06:00 List-Id: "Keith Thompson" wrote in message news:ln8y8932ei.fsf@nuthaus.mib.org... > "Randy Brukardt" writes: > > "Jeffrey Carter" wrote in message > > news:H1Hsd.1987$yr1.256@newsread3.news.pas.earthlink.net... > >> 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?). > > > > The ARG discussed this long ago, and concluded that such a facility isn't > > needed. That's because Unchecked_Conversion provides the needed support. > > Indeed, this is one of the few cases where the result of > > Unchecked_Conversion is defined by the language (using it in this way will > > work on all Ada compilers). There was some discussion about syntax guides > > that prohibit the use of Unchecked_Conversion, but there is a lot of > > discomfort about changing the language just because some people's style > > guides are broken... > > How do you portably choose the target type for the Unchecked_Conversion? > > The 'Pos attribute returns a result of type universal_integer; there's > no way to make an Unchecked_Conversion return a universal_integer. You have to declare a type for that purpose, but otherwise there is no problem: First_Rep : constant := ; Last_Rep : constant := ; type Enum is (First, ...., Last); for Enum use (First => First_Rep, .... Last => Last_Rep); type Enum_Rep is range First_Rep .. Last_Rep; for Enum_Rep'Size use Enum'Size; function To_Rep is new Ada.Unchecked_Conversion (Enum, Enum_Rep); function From_Rep is new Ada.Unchecked_Conversion (Enum_Rep, Enum); All of this is portable, and required for any Annex C compliant compiler. The only loss here is writing a bit of extra text (these declarations, and type conversions on the results of the functions). This is a rare enough need that that doesn't seem too bad. Randy.