comp.lang.ada
 help / color / mirror / Atom feed
From: Ken Garlington <kennieg@flash.net>
Subject: Re: 'size attribute inheritance
Date: 1997/08/11
Date: 1997-08-11T00:00:00+00:00	[thread overview]
Message-ID: <33EFCB66.285D@flash.net> (raw)
In-Reply-To: dewar.871238340@merv


Robert Dewar wrote:
> 
> <<     When running this code, we get a bus alignment error.  We tracked
> it
>      down to the fact that the compiler does NOT really allocate 16 bits
>      for Month with subtype Month_Type.  We assumed that since>>
> 
> This is definitely a compiler bug, there is no way that legal declarations
> that are accepted by the compiler can lead to bus errors.

This seems like an odd statement. Maybe I'm not understanding the
problem,
but I thought the real issue was code like the following:

  package A_Test is

    Word : constant := 4;

    type Small_Value is range 0 .. 15;

    type A_Record is record
      Component_1 : Integer;
      Component_2 : Small_Value;
    end record;

    for A_Record use record
      Component_1 at 0*Word range 0 .. 31;
      Component_2 at 1*Word range 0 .. 31;
    end record;

    My_Record : A_Record := (3, 15);

  end A_Test;

For this code, will My_Record.Component_2 be stored in
bits 0 .. 3 of word 1, bits 28 .. 31, or elsewhere?
I know in Ada83 that this sometimes ended up on one
side, and something like

  type B_Array is array(0 .. 3) of Boolean;
  pragma Pack(B_Array);

sometimes ended up on the other side.

Is there something in the Ada83/Ada RMs that discuss this?
I couldn't find it.

> 
> However, the treatment of the size attribute seems to be quite in accord
> with the RM. Ada 95 effectively introduced pretty serious incompatibilites
> in the handling of 'Size by requiring an interpretaytion that was legal
> in Ada 83 (and happened by no mere coincidence to be the one used by
> the Intermetrics compiler :-) but was not typical of Ada 83 compilers.
> 
> So a lot of old code breaks but the break should consist of rejections
> at compile time: NOT bus errors!

Yeah, I don't think 'Size is really the issue here. It's the behavior
when a record representation clause allocates more space to a component
that it needs. Unless there's something in the RM that controls this,
I could see where a compiler might do something different than you might
expect. For example, storing it in an "unconventional" manner might
allow for fewer shift/mask instructions.

> 
> GNAT has introduced new attributes Value_Size and Object_Size wjhich can
> be applied to subtypes as well as first named types, to provide complete
> control over sizes, and allow old code to be easily ported no matter what
> conventions the compiler on which it was compiled was using.
> 
> Our default conventions are as close as we are allowed to the VADS compiler,
> but we are not allowed to be 100% compatible. In any case the bus error
> is a serious bug. From the description, it does not sound like you are
> using GNAT, and certainly the current version of GNAT does what you
> expect with the declarations you gave.




      parent reply	other threads:[~1997-08-11  0:00 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-08-09  0:00 'size attribute inheritance Carlos Palenzuela
1997-08-10  0:00 ` Robert A Duff
1997-08-10  0:00 ` Matthew Heaney
1997-08-11  0:00   ` Robert Dewar
1997-08-12  0:00     ` Matthew Heaney
1997-08-13  0:00       ` Ken Garlington
1997-08-13  0:00         ` Matthew Heaney
1997-08-13  0:00       ` Robert A Duff
1997-08-13  0:00         ` Matthew Heaney
1997-08-14  0:00           ` Robert A Duff
1997-08-14  0:00             ` Dale Stanbrough
1997-08-16  0:00           ` Robert Dewar
1997-08-16  0:00             ` Ken Garlington
1997-08-17  0:00               ` Robert Dewar
1997-08-18  0:00                 ` Robert A Duff
     [not found]                   ` <dewar.872433846@merv>
1997-09-03  0:00                     ` Robert A Duff
1997-09-06  0:00                       ` Robert Dewar
1997-09-08  0:00                         ` Robert A Duff
1997-08-17  0:00               ` Robert A Duff
1997-08-10  0:00 ` Robert Dewar
1997-08-11  0:00   ` Matthew Heaney
1997-08-11  0:00   ` Ken Garlington [this message]
replies disabled

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