comp.lang.ada
 help / color / mirror / Atom feed
From: "Dan'l Miller" <optikos@verizon.net>
Subject: Re: AI12-0218: What is the portable representation clause for processing IETF packets on little-endian machines?
Date: Thu, 10 May 2018 19:38:59 -0700 (PDT)
Date: 2018-05-10T19:38:59-07:00	[thread overview]
Message-ID: <5c9b9f90-884f-4de7-8663-d39a67949f4f@googlegroups.com> (raw)
In-Reply-To: <flk0a3Fpvi4U1@mid.individual.net>

On Thursday, May 10, 2018 at 5:44:21 PM UTC-5, Niklas Holsti wrote:
> Both the example, and the Erlang reference manual section linked from 
> the example, describe an "endianness" attribute that can be given one of 
> the values "big", "little", "native", with default "big".

Ah, yes, now I see it.  Thank you for pointing that out.  I apologize, Paul.

> However, it 
> seems this attribute applies only to a restricted set of types: integer, 
> utf16, utf32 and float.
> 
> It is not clearly explained how endianness is interpreted for fields 
> that do not align with octet boundaries.

Ah, Paul & Randy & Dmitry, right there might be the best card for the opposition to play:  endianness (independent of Ada's record representation clauses) has absolutely nothing at all to do with arbitrary bitfields.  Endianness exists when reading 16-, 32-, 64-, 80-, 128-, 256-, and 512-bit words from memory or writing them to memory.  Hence, incorrect endianness of processing, say, an IETF packet header depends on the ••word size (arbitrarily chosen to be) utilized by the software•• to (capriciously) access the fields within (or crossing the boundaries of) that 16-, 32-, 64-, etc-bit word, not the •record itself•.  It only becomes part of the record per se when trying to utilize Ada's record representation clauses or C's struct-of-bitfields type-casting.  Endianness is on a plane above the fields of the record—the parent nodes of a tree (of word boundaries) hovering above the record, casting a shadow of these boundary-lines, so to speak, on the bitwise fields that might not be byte or word aligned at all, within the words or crossing the boundary of words.

Still, standard Ada has no good Ada-esque solution to heterogenous endianness at the perimeter of a system, other than writing C-esque pointer-arithmetic code with the various unchecked_ constructs (which even C programmers don't generally do; they utilize conditionally-compiled macros that correctly type-cast meticulously*-laid-out structs-of-bitfields onto that packet's header or IC register's word.

* on a per-processor, per-toolchain basis, selected via the conditional compilation via the C preprocessor.  This selection (out of nonportable categorization) is what accomplishes the portability.  Ada has no equivalent other than AI32-0218's/GNAT's solution.

  parent reply	other threads:[~2018-05-11  2:38 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-10 17:45 AI12-0218: What is the portable representation clause for processing IETF packets on little-endian machines? Dan'l Miller
2018-05-10 19:24 ` Dan'l Miller
2018-05-10 20:32   ` Paul Rubin
2018-05-10 22:24     ` Dan'l Miller
2018-05-10 22:44       ` Niklas Holsti
2018-05-10 23:14         ` Paul Rubin
2018-05-11  2:38         ` Dan'l Miller [this message]
2018-05-11  7:55           ` Simon Wright
2018-05-11 12:11             ` Lucretia
2018-05-11 13:49               ` Simon Wright
2018-05-11 16:11                 ` Jeffrey R. Carter
2018-05-11 16:48                   ` Simon Wright
2018-05-11 19:08                     ` Jeffrey R. Carter
2018-05-11 21:39                       ` Simon Wright
2018-05-11 21:56                         ` Jeffrey R. Carter
2018-05-12  7:08                           ` Simon Wright
2018-05-12  7:53                             ` Jeffrey R. Carter
2018-05-14 22:43                             ` Randy Brukardt
2018-05-11 13:46             ` Simon Wright
2018-05-11 22:12           ` Randy Brukardt
2018-05-12 10:33             ` Björn Lundin
2018-05-12 13:08               ` Simon Wright
2018-05-12 14:21                 ` Björn Lundin
2018-05-10 23:07       ` Paul Rubin
2018-05-11  0:14         ` Dan'l Miller
2018-05-11  0:30           ` Paul Rubin
2018-05-11  0:50             ` Dan'l Miller
2018-05-11  1:34               ` Paul Rubin
2018-05-11  2:11                 ` Dan'l Miller
2018-05-11 22:32                   ` Randy Brukardt
2018-05-11  8:02         ` Simon Wright
2018-05-11 22:14         ` Randy Brukardt
2018-05-10 19:28 ` Simon Wright
2018-05-10 22:40   ` Randy Brukardt
2018-05-10 22:50     ` Dan'l Miller
2018-05-11 22:00       ` Randy Brukardt
2018-05-12  1:15         ` Paul Rubin
2018-05-14 22:54           ` Randy Brukardt
2018-05-15  0:43             ` Paul Rubin
2018-05-15 21:39               ` Randy Brukardt
2018-05-15  0:44             ` Dennis Lee Bieber
2018-05-11  8:09     ` Simon Wright
2018-05-10 19:34 ` Dmitry A. Kazakov
2018-05-10 20:06   ` Dan'l Miller
2018-05-10 22:44     ` Paul Rubin
2018-05-10 22:50     ` Randy Brukardt
2018-05-11  9:40       ` Niklas Holsti
2018-05-11 11:40         ` Dan'l Miller
2018-05-11 20:16           ` Niklas Holsti
2018-05-11  9:40     ` Dmitry A. Kazakov
2018-05-11 14:21 ` AdaMagica
2018-05-26 16:15 ` Dan'l Miller
2018-05-26 19:02   ` AdaMagica
2018-05-26 21:01     ` Dan'l Miller
2018-05-27 14:58       ` AdaMagica
2018-05-27 18:03         ` Simon Wright
2018-05-29 22:17           ` Randy Brukardt
2018-05-30  6:39             ` Simon Wright
2018-05-30  7:25               ` Dmitry A. Kazakov
2018-05-30 15:01                 ` Simon Wright
2018-05-30 15:59                   ` Dan'l Miller
2018-05-30 19:38               ` Randy Brukardt
2018-05-27 18:04         ` Dan'l Miller
replies disabled

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