Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 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