comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@merv.cs.nyu.edu (Robert Dewar)
Subject: Re: Help needed in port to GNAT95 from verdix
Date: 1998/05/14
Date: 1998-05-14T00:00:00+00:00	[thread overview]
Message-ID: <dewar.895190155@merv> (raw)
In-Reply-To: Esyp0E.5q0@world.std.com


Bob Duff said

<<Byte'Size will be 8 by default, given the above.  Also, if you say:

    type Byte is range 0..2**8-1;

then Byte'Size will still be 8 by default.  (And of course you can say
"for Byte'Size use 8;" in either case; you're just confirming the
default.)
>>


Technically true, but *highly* misleading. The RM is badly flawed in the
area of size (the 83 RM was better, because it left things looser, the
Ada 95 RM tried to tighten things up and got it wrong!)

Yes, it is true that Byte'Size will be 8 by default (because this is what
the Ada 95 -- rather mistakenly -- requires). But the Ada 95 RM does NOT
require that objects of type Byte take 8 bits. 

The trouble is that most people think of the size of an object as being
determined by the size of the type, but that is generally not true in 
Ada 95 (though it was typically true in the default case in Ada 83).

Consider:

	type r is range 0 .. 5;

A typical Ada 83 implementation will likely make the size of "r" objects be
8 bits, and set r'size to 8. 

A typical Ada 95 implementation will likely make the size of "r" objects be
8 bits, but r'size is required to be 3.

We have found in GNAT that the most compatible approach (i.e. compatible
to typical Ada 83 implementations), is to make the size of objects of a
given subtype by default take up the same size as the base type, regardless
of subtype range. So in GNAT:

    type Byte is range 0..2**8-1;

since Byte'Base is obviously required to be large than 8 bits, we allocate
16 bits by default for objects of type Byte. This can of course be
overridden by giving a size clause, either for the object OR FOR THE TYPE, so
in GNAT

    for Byte'Size use 8;

causes objects to by 8 bits by default.

If you are only using GNAT, the entire size mess is cleaned yup nicely by
use of the implenmentation defined attributes Object_SIze and Value_Size
which properly separate these two aspects of Size. In Ada 83, it was left
rather vague as to which of these two was being talked about. In Ada 95,
the RM requires that the SIze attribute return the size of values, rather
than the size of objects.

That's a mistake in my view, but it's too late now.

Note: the latest version of GNAT implements an attribute
VADS_Size, which gives exactly the size value that would have been
given by the VADS Ada 83 compiler (some of our customers found that the
incompatible changes to the meaning of 'Size were just too extensive
to be fixable).

FOr example, the common Ada 83 paradigm for do it yourself streams, namely
using 'Size on the type of an object to find out how many bits to read
or write, is likely to break badly in Ada 95 ports of such code.





  parent reply	other threads:[~1998-05-14  0:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-05-13  0:00 Help needed in port to GNAT95 from verdix Paul Hussein
1998-05-14  0:00 ` Mats Weber
1998-05-14  0:00   ` Charles Hixson
1998-05-14  0:00     ` Matthew Heaney
     [not found]     ` <Esyp0E.5q0@world.std.com>
1998-05-14  0:00       ` Robert Dewar [this message]
1998-05-15  0:00         ` Larry Kilgallen
1998-05-19  0:00           ` John McCabe
1998-05-15  0:00         ` Jean-Pierre Rosen
1998-05-16  0:00           ` Robert Dewar
1998-05-15  0:00 ` Niklas Holsti
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox