Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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
types.

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
string.

> 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.