From: "Loup Vaillant" <loup.vaillant@gmail.com>
To: "Oliver Bandel" <oliver@first.in-berlin.de>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Concatenation of static strings?
Date: Fri, 25 Jan 2008 11:47:37 +0100 [thread overview]
Message-ID: <6f9f8f4a0801250247w37d4c66q1b268e47a72ecabf@mail.gmail.com> (raw)
In-Reply-To: <1201226223.479941ef07943@webmail.in-berlin.de>
2008/1/25, Oliver Bandel <oliver@first.in-berlin.de>:
> Zitat von Ashish Agarwal <agarwal1975@gmail.com>:
>
> > I was hoping there would be some follow up discussion on the code
> > below, but
> > haven't seen anything yet.
> [...]
>
> [...]
> It behaves like if s would be defined on top of the
> module, but it is local constructed in the function f.
> Look sstrange... I have the same behaviour here (Debians
> OCaml here is 3.09.2, and I have tried with toplevel, bytecode
> and naticecode).
Ouch: this is the same as in C: the attempt to modify a statically
defined string makes bad things happen. One should try this on Open
BSD: it may even crash, if the the data segment is protected from
write. Replacing "abc" by String.copy "abc" works around this, though:
# let f () = let s = String.copy "bla" in let c = s.[0] in s.[0] <- 'c' ; c ;;
val f : unit -> char = <fun>
# f();;
- : char = 'b'
# f();;
- : char = 'b'
Pure again :-)
Cheers,
Loup
next prev parent reply other threads:[~2008-01-25 10:47 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-19 3:32 Erik de Castro Lopo
2008-01-19 6:50 ` [Caml-list] " David Allsopp
2008-01-19 7:36 ` Erik de Castro Lopo
2008-01-19 10:55 ` David Baelde
2008-01-24 23:02 ` Ashish Agarwal
2008-01-25 1:57 ` Oliver Bandel
2008-01-25 10:47 ` Loup Vaillant [this message]
2008-01-26 13:27 ` Ashish Agarwal
2008-01-26 16:13 ` Jon Harrop
2008-01-26 19:58 ` Oliver Bandel
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=6f9f8f4a0801250247w37d4c66q1b268e47a72ecabf@mail.gmail.com \
--to=loup.vaillant@gmail.com \
--cc=caml-list@yquem.inria.fr \
--cc=oliver@first.in-berlin.de \
/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