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=-0.5 required=5.0 tests=BAYES_00,INVALID_MSGID, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,49c69fcb0de2bb74 X-Google-Attributes: gid103376,public From: "Jean-Pierre Rosen" Subject: Re: Types vs subtypes Date: 2000/08/29 Message-ID: <8ogfim$e2t$1@wanadoo.fr>#1/1 X-Deja-AN: 663896956 References: <39a9d2b0@duster.adelaide.on.net> <39AAF3AB.3E5EE43E@ix.netcom.com> <39ABAAE7.3B4BEF29@lmco.com> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 X-Complaints-To: abuse@wanadoo.fr X-Trace: wanadoo.fr 967557526 14429 193.250.53.161 (29 Aug 2000 13:58:46 GMT) Organization: Adalog X-MSMail-Priority: Normal NNTP-Posting-Date: 29 Aug 2000 13:58:46 GMT Newsgroups: comp.lang.ada Date: 2000-08-29T13:58:46+00:00 List-Id: "Marc A. Criley" a �crit dans le message news: 39ABAAE7.3B4BEF29@lmco.com... > We had a situation where there was a > > type Counts is range 0..128; > > that had a size clause: > > for Counts'Size use 32; > > This then had a subtype > > subtype Indicies is Counts range 1..128; > > Our expectation was that Counts'Size would be 32, and Indices'Size would be 32. > While that was in fact the case for the 'Size of Counts, Indices'Size turned out to > be 8. We researched this in the RM (and could find no statement requiring that a > type's size be passed on to its subtypes), and also went back to our compiler > vendor, and confirmed that this behavior was correct. It was, as Robert Dewar put > it, "in pure Ada 95...a nasty omission". While size specification is retained > through derivation, it is not through subtyping. And placing a Size specification > on a subtype is not permitted by the language. > > We ended up utilizing the parent type in the external interface, relying on the use > of the subytpe throughout the remainder of the module to ensure the proper > constraints were obeyed. It seems that you assumed that *variables* declared of subtype Indices would use Indices'Size bits - and this is a misunderstanding. Try this: with Text_Io; use Text_Io; procedure Essai is type Counts is range 0..128; for Counts'Size use 32; subtype Indices is Counts range 1..128; V_Counts : Counts; V_Indices : Indices; begin Put_Line ("Sizes:"); Put_Line ("Counts:" & Integer'Image (Counts'Size)); Put_Line ("Indices:" & Integer'Image (Indices'Size)); Put_Line ("V_Counts:" & Integer'Image (V_Counts'Size)); Put_Line ("V_Indices:" & Integer'Image (V_Indices'Size)); end Essai; You'll see (with Gnat) that V_Indices has size 32. In short: the 'Size for a (sub)type tells you the minimum number of bits required for it according to Shannon's theorem. If you want to check the size used by a variable, declare a variable and take its 'size. -- --------------------------------------------------------- J-P. Rosen (Rosen.Adalog@wanadoo.fr) Visit Adalog's web site at http://pro.wanadoo.fr/adalog