comp.lang.ada
 help / color / mirror / Atom feed
From: "Marc A. Criley" <mcquad2@earthlink.net>
Subject: Re: Green Hiils AdaMULTI 2000 -> Motorola Coldfire
Date: Fri, 12 Jan 2001 13:18:49 GMT
Date: 2001-01-12T13:18:49+00:00	[thread overview]
Message-ID: <3A5EF610.66C153D2@earthlink.net> (raw)
In-Reply-To: 3A5DC6D5.5A8446D8@hercii.mar.lmco.com

One other aspect regarding 'Size, types, and subtypes.  This one bit us
when porting from Alsys Ada 83 to GNAT.

If a type has a 'Size clause applied to it, specifying a size larger
than what is actually required, and a subtype off that type is defined,
the subtype does _not_ inherit the parent's size specification.  For
example:

   type Counts is range 0..128;
   for Counts'size use 32;

   subtype Subcounts is Counts range 1..128;

then
   Counts'Size is 32
   Subcounts'Size is 8

This is caused by a gap in the Ada 95 definition regarding "sizes",
which I think Robert Dewar alluded to in an earlier message.  I don't
recall the LRM reference that results in this behavior, but it's
defininely there and one is barred from making the behavior otherwise.

I recall, though, ACT informing me that _objects_ of either of those
Counts or Subcounts types would occupy the requested 32 bits (and they
do in GNAT)--I believe there was some implementation freedom regarding
that aspect.

In the few places where we had to deal with this situation, we simply
replaced the subtype with the parent type at, and only at, the place
where the difference in size had an effect.  Everywhere else we
continued to use the subtype to ensure proper type constraining.

Marc A. Criley
Senior Staff Engineer
Quadrus Corporation
www.quadruscorp.com




Brian Courtney wrote:
> 
> We recently ported a 200,000+ sloc app (MIPS) from Ada83 (Aonix)
> to GHS Ada95 as part of an evaluation of the AdaMULTI2000
> environment.  The only problem we experienced was not
> with the compiler/environment, rather some bad assumptions
> made by the original developers about the size of subtypes.
> NOTE: The language does not require objects of a subtype to
> be the same size as objects of the parent type.  As you
> might expect, the two compilers implemented this differently.
> The Aonix Ada83 compiler would preserve the size of subtypes
> from the parent type and the GHS Ada95 compiler would not (it
> seemed to chose the smallest size possible based on the range
> of the subtype).  Either implementation is allowed by the language.
> 
> A misunderstanding by the developers, or an oversight in the
> language? Either way, this issue has plagued more than one
> project, so it may be something you want to be on the lookout for.
> I've used XDAda in the past, but can't recall its behavior.  In any
> event, the moral of the story is "don't assume the size of a subtype".
> 
> Hope this helps,
> 
> Brian Courtney



  parent reply	other threads:[~2001-01-12 13:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-01-10 20:26 Green Hiils AdaMULTI 2000 -> Motorola Coldfire Mark Fisher
2001-01-11  8:56 ` Martin Dowie
2001-01-11 14:03   ` Tucker Taft
2001-01-11 14:22     ` Martin Dowie
2001-01-11 20:47       ` Larry Kilgallen
2001-01-11 14:44 ` Brian Courtney
2001-01-11 20:51   ` Robert Dewar
2001-01-12 13:18   ` Marc A. Criley [this message]
2001-01-12 17:44     ` Robert Dewar
replies disabled

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