Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Unsafe features
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-09-03 (14:29)
From: Florian Weimer <fw@d...>
Subject: Re: [Caml-list] Unsafe features
* yoann padioleau:

>> Apparently, it creates a bit-wise copy of a value and assigns it a new
>> type.
> Are you sure ? I thought it was just a function to get rid temporary
> of the typing system, a kind of cast operator.

It is, but how would you define such a operator?  At a more abstract
level, there is no obvious choice for a map a -> b between arbitrary

I gave it a try and got:

# let x : int = Obj.magic "x";;
val x : int = 67381588
# x;;
- : int = 67381588

The "67381588" is just half the integral value of a heap address
(because of the tag bit, I presume).  And looking at the ltrace
output, it seems that it is indeed close to the storage area of that

> But is is bad to use it, very bad, shame on you if you use it
> (i just put this statement to be sure that xavier leroy will not  
> shout over me).

Yes, and my question was to avoid such unsafe language features.