Browse thread
Concatenation of static strings?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Loup Vaillant <loup.vaillant@g...> |
| Subject: | Re: [Caml-list] Concatenation of static strings? |
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