comp.lang.ada
 help / color / mirror / Atom feed
From: bobduff@world.std.com (Robert A Duff)
Subject: Re: Interfacing Ada to C
Date: 1997/05/30
Date: 1997-05-30T00:00:00+00:00	[thread overview]
Message-ID: <EB0285.Kw@world.std.com> (raw)
In-Reply-To: m3afle72cl.fsf@zaphod.enst.fr


In article <m3afle72cl.fsf@zaphod.enst.fr>,
Samuel Tardieu  <sam@ada.eu.org> wrote:
>  type My_Natural is range 0 .. 15;
>  for My_Natural'Size use 4;

The 'Size clause should not be necessary.  My_Natural'Size = 4 by
default.  At least this is true for a compiler that conforms to the SP
Annex -- without that, most of chapter 13 means nothing anyway.

>  type R is record
>    A, B : My_Natural;
>  end record;
>  pragma Pack (R);
>  for R'Size use 8;
>
>If you do:
>
>  My_R : aliased constant R := (1, 2);
>
>then My_R will be represented in memory by a single byte containing
>00010010 (or 00100001, depending on the endianness).

That's misleading.  The RM says that it will fit in 8 bits.  The RM says
nothing about the order of the components.  The order need not have
anything to do with endianness -- it's up the whim of the compiler
writer.  Consider a record with three components -- there are 6 possible
orders to lay them out in memory (assuming the compiler isn't doing
anything really weird, like splitting components into pieces), and the
compiler can choose any one of those 6.  Some of those orders may be
more efficient than others.  I would like my compiler to choose an
efficient order (unless I do pragma Convention(C) or whatever, in which
case I want the order to match the source code).  I want to write my
record type in some logical order, without worrying too much about what
the most efficient layout is.  This is true whether or not I choose to
use pragma Pack.

- Bob




  reply	other threads:[~1997-05-30  0:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-05-29  0:00 Interfacing Ada to C Rune Wemberg
1997-05-29  0:00 ` Robert Dewar
1997-05-29  0:00 ` Samuel Tardieu
1997-05-30  0:00   ` Robert A Duff [this message]
1997-05-30  0:00   ` Matthew Heaney
1997-05-31  0:00     ` Robert A Duff
1997-06-07  0:00       ` Robert Dewar
1997-05-30  0:00 ` Robert A Duff
  -- strict thread matches above, loose matches on Subject: below --
1999-06-14  0:00 Drew
1999-06-14  0:00 ` Steve Quinlan
1999-06-14  0:00 Drew
replies disabled

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