From: Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk>
Subject: Re: Size of 0..255 is not 8 bits?
Date: 1998/05/14
Date: 1998-05-14T00:00:00+00:00 [thread overview]
Message-ID: <355AEA1D.6C292667@cl.cam.ac.uk> (raw)
In-Reply-To: matthew_heaney-ya023680001305982154260001@news.ni.net
Matthew Heaney wrote:
> Better is to throw a size clause on your object:
>
> type Value is range 0..255;
> V : Value;
> for V'Size use 8;
This did not change anything, V is still a 16-bit integer. I get
no difference whether the 'Size clause is for the type, the object,
both or none at all. Only
type Value is mod 2**8;
gave me really an 8-bit unsigned integer variable.
> Throw a size clause on your object V, and see what that does.
Nothing.
I see, why 0..255 requires an at least 9-bit signed type, but
I am somewhat disappointed that neither the type'Size nor the
object'Size clause gives me a compiler warning that this is not
an 8-bit type.
So all this IMHO means that either gnat-3.10p contains an error
here or that John Barnes wrote nonsense in "Programming in Ada95",
1996, p. 526, where he writes "Thus
type Byte is range 0..255;
for Byte'Size use 8;
indicates that objects of the type Byte should occupy only 8 bits."
The weirdest effect is that if I read the file content "ABCDEFGH...",
I get only every second byte (65 67 69 ...) with Value'Read,
and not as I would have expected a sequence of 16-bit values
(65+66*2**8 67+68*2**8 ...) or constraint errors.
Any guru insight?
Other question: If the rest of a stream is too short for a
T'Read to succeed, what is supposed to happen? Constraint error?
The ARM doesn't say much on this subject.
Markus
--
Markus G. Kuhn, Security Group, Computer Lab, Cambridge University, UK
email: mkuhn at acm.org, home page: <http://www.cl.cam.ac.uk/~mgk25/>
next prev parent reply other threads:[~1998-05-14 0:00 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-05-14 0:00 Size of 0..255 is not 8 bits? Markus Kuhn
1998-05-13 0:00 ` Matthew Heaney
1998-05-14 0:00 ` Tom Moran
1998-05-14 0:00 ` Robert Dewar
1998-05-14 0:00 ` Markus Kuhn [this message]
1998-05-14 0:00 ` John McCabe
1998-05-14 0:00 ` Robert Dewar
1998-05-14 0:00 ` Robert Dewar
1998-05-14 0:00 ` Simon Pilgrim
1998-05-15 0:00 ` Markus Kuhn
1998-05-15 0:00 ` Samuel T. Harris
1998-05-15 0:00 ` Tucker Taft
1998-05-15 0:00 ` Joe Gwinn
1998-05-16 0:00 ` Robert Dewar
1998-05-17 0:00 ` Joe Gwinn
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox