comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Adding offset to 'Address
Date: Fri, 12 Sep 2008 17:37:48 -0700 (PDT)
Date: 2008-09-12T17:37:48-07:00	[thread overview]
Message-ID: <be0df487-dd85-4907-9073-8c23cc475c09@25g2000prz.googlegroups.com> (raw)
In-Reply-To: wccy71xjb4q.fsf@shell01.TheWorld.com

On Sep 12, 2:40 pm, Robert A Duff <bobd...@shell01.TheWorld.com>
wrote:
> Adam Beneschan <a...@irvine.com> writes:
> >   (Ethernet_Header'Size + System.Storage_Unit - 1) /
> > System.Storage_Unit
>
> > which rounds the size in bits up to the next multiple of
> > System.Storage_Unit.  [System.Storage_Unit will equal 8 on most
> > systems.]
>
> It seems to me that this sort of thing won't work unless
> System.Storage_Unit is 8 bits.  So you don't want rounding up.
> It seems better to say:
>
>     pragma Assert (System.Storage_Unit = 8);
>     ... Raw_Bytes.all'Address + Ethernet_Header'Size/8 ...
>
> If you really need to do this sort of thing, that is.

That's very likely to work.  I'd still worry that, since the
definition of 'Size is slightly fuzzy, an implementation could still
choose a value that is not a multiple of 8 in a surprising way:

   type Rec1 is record
      Value_1 : Integer;  -- 32 bits, say
      Value_2 : Integer;
      Control_Flag : Boolean;
   end record;

On an 8-bit machine, is Rec1'Size 72 or 65?  I don't think the RM
provides an answer to this.  The minimum size required to represent
Rec1 is 65, and an implementation *could* decide that if Rec1 were a
component of a larger record, and that larger record has another
Boolean component, it could stick that component in the same byte as
Control_Flag.  Or it could just always allocate 9 bytes for Rec1
regardless.  So I still think rounding up is a good idea:

    pragma Assert (System.Storage_Unit = 8);
     ... Raw_Bytes.all'Address + (Ethernet_Header'Size+7)/8 ...

But the real answer, I think, is that if you're going to be using this
type for communication with other machines, you need to use
representation clauses to specify every detail of the type anyway,
including a 'Size clause:

   for Ethernet_Header'Size use ...;

and now you can make sure that it's a multiple of 8:

     pragma Assert (System.Storage_Unit = 8);
     pragma Assert (Ethernet_Header'Size mod 8 = 0);

     ... Raw_Bytes.all'Address + Ethernet_Header'Size/8 ...

                                    -- Adam



  reply	other threads:[~2008-09-13  0:37 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-12  8:35 Adding offset to 'Address Kim Rostgaard Christensen
2008-09-12  9:47 ` Georg Bauhaus
2008-09-12 10:17   ` Kim Rostgaard Christensen
2008-09-12 11:18     ` petter_fryklund
2008-09-12 15:23 ` Adam Beneschan
2008-09-12 21:40   ` Robert A Duff
2008-09-13  0:37     ` Adam Beneschan [this message]
2008-09-13  6:21   ` tmoran
2008-09-17  9:15     ` Kim Rostgaard Christensen
2008-09-19  6:09       ` Randy Brukardt
2008-09-19  9:25         ` anon
2008-09-13 10:18 ` Björn
2008-09-17  9:18   ` Kim Rostgaard Christensen
replies disabled

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