caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Nicolas George <nicolas.george@ens.fr>
To: David MENTRE <dmentre@linux-france.org>
Cc: Caml mailing list <caml-list@inria.fr>
Subject: Re: [Caml-list] How to handle endianness and binary string conversion for 32 bits integers (Int32)?
Date: Thu, 16 Jun 2005 22:14:25 +0200	[thread overview]
Message-ID: <20050616201425.GA25422@clipper.ens.fr> (raw)
In-Reply-To: <87aclqm725.fsf@linux-france.org>

[-- Attachment #1: Type: text/plain, Size: 1224 bytes --]

L'octidi 28 prairial, an CCXIII, David MENTRE a écrit :
> Except that I'm writing a network interface that should be specified so
> that externally written programs can read my data.

My point is: you do not need to convert between big and little endian, you
only have to convert between sequences of bytes and integers. You never need
even to know that integers are stored as bytes in the memory of the
computer.

In fact, I expect that you could not find access to the internal
representation of integers in OCaml, which is a good thing. Most of the
portability bugs in C come from people who have not understood the principle
of having access to the internal representation of objects (which is not to
use it :-). Alas, a lot of books about C are very i86-centered and explain
it really badly.

> In fact, your post reminded me of a chapter of "The Practice of
> Programming" by Kernighan and Pike. They advise to read/write integers
> byte by byte using 8 bit masking and shifting.
> 
> So I'll follow that approach, which is close to yours and is independent
> of machine endianness.

I think this is really exactly the same approach, and I am flattered to have
the same position af Kernighan.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 185 bytes --]

  reply	other threads:[~2005-06-16 20:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-16 18:25 David MENTRE
2005-06-16 19:02 ` [Caml-list] " Nicolas George
2005-06-16 19:32   ` David MENTRE
2005-06-16 20:14     ` Nicolas George [this message]
2005-06-17  7:29     ` Luca Pascali
2005-06-16 22:25 ` Nicolas Cannasse
2005-06-17 18:10   ` David MENTRE

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050616201425.GA25422@clipper.ens.fr \
    --to=nicolas.george@ens.fr \
    --cc=caml-list@inria.fr \
    --cc=dmentre@linux-france.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).