From: Ivan Gotovchits <ivg@ieee.org>
To: Nicolas Trangez <nicolas@incubaid.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Bug in caml_string_get16?
Date: Tue, 05 Nov 2013 07:54:37 +0400 [thread overview]
Message-ID: <87a9hjmrk2.fsf@golf.niidar.ru> (raw)
In-Reply-To: <1383605662.24373.7.camel@tau.nicolast.be> (Nicolas Trangez's message of "Mon, 04 Nov 2013 23:54:22 +0100")
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
Good luck!
--
(__)
(oo)
/------\/
/ | ||
* /\---/\
~~ ~~
...."Have you mooed today?"...
next prev parent reply other threads:[~2013-11-05 3:54 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 [this message]
2013-11-05 9:53 ` Nicolas Trangez
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=87a9hjmrk2.fsf@golf.niidar.ru \
--to=ivg@ieee.org \
--cc=caml-list@inria.fr \
--cc=nicolas@incubaid.com \
/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