From: Nicolas Trangez <nicolas@incubaid.com>
To: Ivan Gotovchits <ivg@ieee.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Bug in caml_string_get16?
Date: Tue, 05 Nov 2013 10:53:24 +0100 [thread overview]
Message-ID: <1383645204.20247.1.camel@tau.nicolast.be> (raw)
In-Reply-To: <87a9hjmrk2.fsf@golf.niidar.ru>
On Tue, 2013-11-05 at 07:54 +0400, Ivan Gotovchits wrote:
> Nicolas Trangez <nicolas@incubaid.com> writes:
>
> > What would you expect to be the output of this code?
>
> It should fail :)
>
> In a string literal any symbol that you can type with your keyboard is
> stored in a special encoding called ASCII. With "1" you have just
> created a string containig a single byte with a value 49. So, first off
> all, your string is too short, because it has length of 1, when int16
> obviously needs two bytes of storage space. If you really interested,
> binary 1 will be represented in a memory of a little endian computer
> like this: "\x01\x00". The special escape symbol "\" allows us to type
> untypable. The the code
>
> open EndianString
> let d = LittleEndian.get_int16 "\x01\x00" 0
>
> will yield:
>
> val d : int = 1
>
> By the way, if we try your string (with a more correct invocation):
>
> open EndianString
> let d = LittleEndian.get_int8 "1" 0
>
> we will got:
>
> val d : int = 49
>
> Futher reading:
>
> 1. man ascii
> 2. wikipedia article on endianess
Oh, don't be mistaken. The question was rhetorical, in order to report a
bug (or get told it's not a bug at all) & provide a test-case :-)
I'm well aware of all of the above ;-)
Thanks!
Nicolas
next prev parent reply other threads:[~2013-11-05 9:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-04 22:54 Nicolas Trangez
2013-11-05 3:54 ` Ivan Gotovchits
2013-11-05 9:53 ` Nicolas Trangez [this message]
2013-11-05 10:49 ` Gabriel Scherer
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=1383645204.20247.1.camel@tau.nicolast.be \
--to=nicolas@incubaid.com \
--cc=caml-list@inria.fr \
--cc=ivg@ieee.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).