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
[Caml-list] Identifying the code part of a closure
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-11-01 (01:56)
From: Alain Frisch <frisch@c...>
Subject: [Caml-list] Identifying the code part of a closure

for some reasons(*), I need to associate to a runtime closure an integer
that identifies its code pointer. Is the following a "safe" solution
for ocamlc and ocamlopt ("safe" means here that it works in all cases,
with the current implementation, under all the architectures where
ocamlopt exists) ?

let addr (h : 'a -> 'b) : int = fst (Obj.magic h);;

Do you see a better way to achieve this ?

-- Alain

(*) for those who are interested, what I'm trying to do is to implement a
functional language by compiling it to OCaml; the closures of the language
map directly to OCaml closures. It turns out that the language has
explicit typing for functions (for instance:  fun (t1 -> t2) x -> ...) and
the semantics of the language has to access the type information (t1 ->
t2) at runtime; all the closures for a function share this piece of
information, so I'd like to store it during program initialization in a
structure indexed by some integer computed from a sample closure of the

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: