March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
13
Task/Address-of-a-variable/OCaml/address-of-a-variable.ocaml
Normal file
13
Task/Address-of-a-variable/OCaml/address-of-a-variable.ocaml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
let address_of (x:'a) : nativeint =
|
||||
if Obj.is_block (Obj.repr x) then
|
||||
Nativeint.shift_left (Nativeint.of_int (Obj.magic x)) 1 (* magic *)
|
||||
else
|
||||
invalid_arg "Can only find address of boxed values.";;
|
||||
|
||||
let () =
|
||||
let a = 3.14 in
|
||||
Printf.printf "%nx\n" (address_of a);;
|
||||
let b = ref 42 in
|
||||
Printf.printf "%nx\n" (address_of b);;
|
||||
let c = 17 in
|
||||
Printf.printf "%nx\n" (address_of c);; (* error, because int is unboxed *)
|
||||
Loading…
Add table
Add a link
Reference in a new issue