comp.lang.ada
 help / color / mirror / Atom feed
* Ada83/95 Compatibility
@ 2005-12-13 18:46 jeff
  2005-12-14  6:18 ` Jeffrey R. Carter
  2005-12-15  0:14 ` Randy Brukardt
  0 siblings, 2 replies; 3+ messages in thread
From: jeff @ 2005-12-13 18:46 UTC (permalink / raw)


I am porting a large batch of Legacy Ada 83 code to an Ada 95 compiler.

One issue i have hit has to do with the 'size of subtypes. (not that
much of a surprise)

I was well aware that there were some differences to be expected in
this area
(e.g. natural'size being 31) but one thing that surprised me is with
this particular
compiler, even object sizes ended up being impacted.

For example

 type My_Big_Int is range -2**31 .. 2**31 -1 ;
 for My_Big_Int'size use 32;

 subtype little_range is My_Big_Int range 0 .. 255;


 A : My_Big_Int;
 B : Little_Range;

I was not surprised that Little_Range'size = 8


What surprised me was that b'size comes back as 8. I've re-read the
representation chapter again and I think the compiler is probably
within its rights to do this.

Since one can't specify a 'size on a subtype like this it appears that
there really is no way to specify a minimum size for a subtype.

While I obviously with B'size = 32 I am not 100% sure that I understand
the chapter well enough to convince myself that it really is a legal
outcome.

..Also note this is not GNAT (which appears to act as I'd expect for
targets I have access to).




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Ada83/95 Compatibility
  2005-12-13 18:46 Ada83/95 Compatibility jeff
@ 2005-12-14  6:18 ` Jeffrey R. Carter
  2005-12-15  0:14 ` Randy Brukardt
  1 sibling, 0 replies; 3+ messages in thread
From: Jeffrey R. Carter @ 2005-12-14  6:18 UTC (permalink / raw)


jeff@thecreems.com wrote:

>  type My_Big_Int is range -2**31 .. 2**31 -1 ;
>  for My_Big_Int'size use 32;
> 
>  subtype little_range is My_Big_Int range 0 .. 255;
> 
>  A : My_Big_Int;
>  B : Little_Range;
> 
> I was not surprised that Little_Range'size = 8
> 
> What surprised me was that b'size comes back as 8. I've re-read the
> representation chapter again and I think the compiler is probably
> within its rights to do this.

This seems correct to me. A value of subtype Little_Range can be stored in 8 
bits (hence its 'Size is 8). What's important is that operations on values of 
Little_Range are done using My_Big_Int'Base.

If you need to store a value in 32 bits (for interfacing to HW, for example) but 
be sure it's in Little_Range, you can always specify the 'Size of the object:

X : Little_Range;
for X'Size use My_Big_Int'Size;

-- 
Jeff Carter
"I soiled my armor, I was so scared."
Monty Python & the Holy Grail
71



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Ada83/95 Compatibility
  2005-12-13 18:46 Ada83/95 Compatibility jeff
  2005-12-14  6:18 ` Jeffrey R. Carter
@ 2005-12-15  0:14 ` Randy Brukardt
  1 sibling, 0 replies; 3+ messages in thread
From: Randy Brukardt @ 2005-12-15  0:14 UTC (permalink / raw)


<jeff@thecreems.com> wrote in message
news:1134499582.913837.213460@g43g2000cwa.googlegroups.com...
...
> Since one can't specify a 'size on a subtype like this it appears that
> there really is no way to specify a minimum size for a subtype.

That's quite right, unfortunately. GNAT has 'Object_Size to deal with this,
and we looked at adding that to Ada 200Y, but it didn't get anywhere (see
AI-319).

Thus, it isn't very useful to specify 'Size on a subtype (it's only real
purpose is to control how tightly components can be packed); it's only
really meaningful on objects.

Hopefully more compilers will support 'Object_Size (we certainly intend to
do so in Janus/Ada).

                            Randy.







^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-12-15  0:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-13 18:46 Ada83/95 Compatibility jeff
2005-12-14  6:18 ` Jeffrey R. Carter
2005-12-15  0:14 ` Randy Brukardt

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