From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e2be1c8e99a1c994 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!25g2000prz.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Adding offset to 'Address Date: Fri, 12 Sep 2008 17:37:48 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1221266268 11352 127.0.0.1 (13 Sep 2008 00:37:48 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 13 Sep 2008 00:37:48 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 25g2000prz.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:2007 Date: 2008-09-12T17:37:48-07:00 List-Id: On Sep 12, 2:40 pm, Robert A Duff wrote: > Adam Beneschan 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