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,233f0e04e488a4a2,start X-Google-Attributes: gid103376,public From: matthew_heaney@acm.org (Matthew Heaney) Subject: Re: Size of 0..255 is not 8 bits? Date: 1998/05/13 Message-ID: #1/1 X-Deja-AN: 353097527 Content-Transfer-Encoding: 8bit References: <355A436E.11F76529@cl.cam.ac.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Organization: Network Intensive Newsgroups: comp.lang.ada Date: 1998-05-13T00:00:00+00:00 List-Id: In article <355A436E.11F76529@cl.cam.ac.uk>, Markus Kuhn wrote: (start of quote) type Value is range 0..255; for Value'Size use 8; V: Value; begin for X in 1..5 loop Value'Read(Stream(Standard_Input), V); Put(Integer(V)); New_Line; end loop; end Strange2; (end of quote) Value'Base has to be implemented with a least 9 bits, because a base type has to be symmetric about zero (the range of Value'Base is at least -255 .. 255). Better is to throw a size clause on your object: V : Value; for V'Size use 8; But I don't know if that will solve your problem. (start of quote) Did I missunderstand something and is S'Size not usable for enforcing the number of bits allocated for a type? Is 0..255 a type for signed 16-bit arithmetic and not a type for (as I had naturally assumed) 8-bit unsigned arithmetic? Do I have to use Unsigned_8 instead if I want to have a guarantee to get an 8-bit word (which doesn't provide arithmetic overflow checks)? (end of quote) Again, this may have something to do with Value'Base requiring a minimum of 9 bits to implement. The RM encourages implementors to use the minimum storage size required for a type, and here, that's 16 bits, as you've confirmed. You could try type Value is range -128 .. 127; or type Value is new Interfaces.Integer_8; (same as above) or type Value is mod 8; or type Value is new Interfaces.Unsigned_8; (same as above) How is Interfaces.Integer_8 implemented? Probably as type Integer_8 is range -128 .. 127; Throw a size clause on your object V, and see what that does. Putting a size clause on a type is pretty misleading. The base range of the type type Value is range 0 .. 255; definately requires 9 bits, so allowing the size clause for Value'Size use 8; is kind of confusing. In fact, a variation of this very problem appears in the AARM 13.3 (55.k). As explained in AARM 13.3 (55.n, 55.o), the "correct" way to handle this is to declare the object as having a size clause. I'm pretty sure that's the answer: put a size clause on the object, not the type.