Re: [dev] Introducing the imagefile-format

From: Staven <>
Date: Tue, 29 Jul 2014 02:25:06 +0200

On Tue, Jul 29, 2014 at 1:59 AM, FRIGN <> wrote:
> Be careful: the n in ntohl does not stand for native, but network.
> More or less by convention, the Network Byte Order today is BE. What
> ntohl makes sure is that in case we are on a LE-system, it's arranged
> properly.
> ntohl is only superfluous here when we are on a BE-machine. [...]

That's what I was assuming. That on a BE machine, ntohl will be a no-op.
Maybe I should spell out my reasoning here.

The bytes in hdr are in Big Endian order.

Unless I have my understanding of bit shifts backwards, this expression:
(hdr[9] << 0) | (hdr[10] << 8) | (hdr[11] << 16) | (hdr[12] << 24)
will result in a BE-ordered (network-ordered) value on LE machines,
and a LE-ordered value on BE machines.

Then, running it through ntohl:
reverses the byte order on LE machines, which gives us an LE-ordered
value (correct)
or does nothing on BE machines, which gives us an LE-ordered value (wrong!).

In any case, I feel like I'm making mountains out of molehills here, and this
example code isn't used anywhere as far as I can see, so I'm not gonna bother
you with this anymore.
Received on Tue Jul 29 2014 - 02:25:06 CEST

This archive was generated by hypermail 2.3.0 : Tue Jul 29 2014 - 02:36:07 CEST