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!news.glorb.com!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: Fri, 10 Dec 2004 13:41:39 -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: Fri, 10 Dec 2004 13:42:57 -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-oLGRogl0C/WCIn/5lDeKyc1FcXpYS8oeICl+n9cLvOkGNtDM9TOpGcToW5jSQ451snUlp0MPW37PE4R!fdhZNoShi36nb68KCpSKFof23bDMGS0eh5ZKl4m6NXKUzSJRrOF4CvgUXkBA/aKxK/v+ScMvhN22 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:6884 Date: 2004-12-10T13:42:57-06:00 List-Id: "Keith Thompson" wrote in message news:ln1xdygaf2.fsf@nuthaus.mib.org... > Here's an example where it doesn't work: ... If you want an unsigned type, then use a modular type: type Enum_Rep is mod 2**Enum'Size; for Enum_Rep'Size use Enum'Size; I know that you're now going to say that that doesn't work for a signed representation, but that's a red herring. You have the know whether the representation is signed or unsigned, even for your hypothetical From_Rep attribute, because you have to decide on what sort of type to put it into. Otherwise, you're at risk of raising Constraint_Error. (On a typical implementation, there are modular values that don't fit into any signed type, and of course negative values don't fit into any modular type.) Even a non-static universal expression isn't safe: it can raise Constraint_Error for modular values that aren't in any signed type. One example: generic type Something is (<>); package P is ... end P; package body P ... if Something'Pos(Something'Last) > 10 then -- (!) ... end P; The expression marked (!) can (and will on many implementations) raise Constraint_Error, because Something'Pos(Something'Last) is outside of the range of Root_Integer. So you really have to know which you are dealing with. For enumeration representations, assuming modular is probably the best option, as you are usually dealing with bit patterns. But this whole issue comes from people trying to use enumeration representations for purposes for which they are not intended. They're only intended to be used for *external* representations, which means that the program itself has no reason to be concerned with them. The program should use the internal representation. If you really need a discontiguous counting type, that's something that Ada doesn't provide and you should program it yourself. That's a very rare need; you really need to think carefully if you really need such a type. The issue is very similar to Bit_Order, which only has to do with the way bits are numbered in the program; it has nothing to do with the bit or byte order in the external world. But people keep hoping that it would be, because that would make someone else solve their hard problems. Randy.