comp.lang.ada
 help / color / mirror / Atom feed
* Size Rep clauses on Ada83 vs. Ada95
@ 1995-03-28 17:08 Bill Priest
  1995-03-29  0:00 ` Tucker Taft
  0 siblings, 1 reply; 3+ messages in thread
From: Bill Priest @ 1995-03-28 17:08 UTC (permalink / raw)


Per 13.2 of Ada Programming Language Reference Manual (MIL-STD-1815a-1983)

" Size specification:  T'SIZE

The expression must be a static expression of some integer type.  The value
of the expression specifies an upper bound for the number of bits to be 
allocated to objects of the type or first named subtype T.  The size 
specification must allow for enough storage space to accommodate every
allowable value of these objects.  A size specification for a composite type
may affect the size of the gaps between the storage areas allocated to 
consecutive components.  On the other hand, it need not affect the size of the
storage area allocated to each component.

The size specification is only allowed if the constraints on T and on its 
subcomponents (if any) are static.  In the case of an unconstrained array type,
the index subtypes must also be static."

Any typos in the above are mine.

Code I have written for the Tartan Ada C3x compiler is behaving incorrectly;
a simple example illustrating the problem follows:

with text_io;
procedure test is

type x_type is new boolean;
for x_type'size use 32;

type y_record_type is 
   record
      one : x_type;
      two : x_type;
   end record;

type position_array_type is array (0 .. 1) of natural;
y : y_record_type;
z : position_array_type;

begin

   z(0) := y.one'position;
   z(1) := y.two'position;
     
   if (z (0) = z (1)) then
      text_io.put_line ("Positions were equal.");
   else
      text_io.put_line ("Positions were not equal.");
   end if;

end test;

The output of running this program is "Positions were equal."

Is this a illegal program or a compiler bug.

Thanks in advance,

Bill



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

* Re: Size Rep clauses on Ada83 vs. Ada95
  1995-03-28 17:08 Size Rep clauses on Ada83 vs. Ada95 Bill Priest
@ 1995-03-29  0:00 ` Tucker Taft
  1995-03-30  0:00   ` Bill Priest
  0 siblings, 1 reply; 3+ messages in thread
From: Tucker Taft @ 1995-03-29  0:00 UTC (permalink / raw)


Bill Priest (bpriest@ti.com) wrote:

: Per 13.2 of Ada Programming Language Reference Manual (MIL-STD-1815a-1983)

: " Size specification:  T'SIZE

: The expression must be a static expression of some integer type.  The value
: of the expression specifies an upper bound for the number of bits to be 
: allocated to objects of the type or first named subtype T.  

This last sentence was effectively overruled by AI-536, even before 
Ada 9X hit the scene.  The official "Ada 83+AIs" rule is now 
that a size clause specifies a *lower* bound for the number of 
bits to be allocated to objects of the subtype T.  
This was for good reason, since the 'size for Standard.Boolean 
was also specified to be 1 by the same AI, but we all
know that it is desirable to give a stand-alone Boolean variable
at least a byte on most machines, and probably a whole word on many
RISC machines.

Since the early days of Ada, there has been a fair amount of disagreement
about the proper interpretation of the size clause.  Hence, if you
want to really control the representation of a record, use a record
representation clause, rather than relying on size clauses to do your
"dirty" work.

We have tried to clarify things a bit in Ada 95, but there is still
some controversy about whether a subtype size clause should have a direct
effect on stand-alone objects, if the specified size is "relatively"
efficient to use.  The final Ada 95 reference manual says:

   If the Size of a subtype is specified, and allows for efficient 
   independent addressibility on the target architecture, then the
   Size of the folllowing objects of the subtype should equal the
   Size of the subtype:
     - Aliased objects (including components)
     - Unaliased components, unless the Size of the component is determined
       by a component_clause or Component_Size clause.

We believe this wording corresponds pretty closely to the intent
of "Ada 83 + AIs," if you ignore the mention of "aliased" (which isn't
trivial to do ;-), though well-informed people still differ a bit on that...

Hence, the recommendation still stands that to be in complete
control, use a record representation clause.  Note also that
the word "should" rather than "shall" appears in the above citation 
from RM95, whereas in the rules on record representation clauses, there 
is no such implementation variability allowed.

: Bill

-Tucker Taft  stt@inmet.com
Intermetrics, Inc.




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

* Re: Size Rep clauses on Ada83 vs. Ada95
  1995-03-29  0:00 ` Tucker Taft
@ 1995-03-30  0:00   ` Bill Priest
  0 siblings, 0 replies; 3+ messages in thread
From: Bill Priest @ 1995-03-30  0:00 UTC (permalink / raw)


Tucker == <stt@inmet.com>

Tucker> Hence, the recommendation still stands that to be in complete
Tucker> control, use a record representation clause.  Note also that
Tucker> the word "should" rather than "shall" appears in the above citation 
Tucker> from RM95, whereas in the rules on record representation clauses, there 
Tucker> is no such implementation variability allowed.

I tried this; but the compiler is so buggy that it no longer would even
believe that one of the fields even existed (i.e. a function call that made
an assignment to the field was "optimized away").  

Thanks for the advice,

Bill
PS.  I reported it as a bug to Tartan; and changed my record to only contain
32 bit quantities (except for the boolean values; which seemed to be ok as
long as they were at the bottom of the record declaration).  Not pretty or
maintainable; but it was the only thing I found that would work.  

PPS. Anyone know where I could get a copy of the latest ACVC's (if possible);
I would like to try to build and run as many tests as possible so that I can
know what types of things the compiler can and cannot handle.




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

end of thread, other threads:[~1995-03-30  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-03-28 17:08 Size Rep clauses on Ada83 vs. Ada95 Bill Priest
1995-03-29  0:00 ` Tucker Taft
1995-03-30  0:00   ` Bill Priest

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