[ create a new paste ] login | about

Link: http://codepad.org/wpRQxPbJ    [ raw code | fork ]

OCaml, pasted on May 26:
open System.Runtime.InteropServices
open System.Reflection

[<Struct>]
[<StructLayout(LayoutKind.Sequential)>]
type x = 
    val mutable t : uint32

[<Struct>]
[<StructLayout(LayoutKind.Sequential)>]
type y = 
     val mutable t : bool



let mutable p = x(t=1u)

p :> y (* error *)

let mutable ptr = Marshal.AllocHGlobal(sizeof<x>);

Marshal.StructureToPtr(p,ptr,false)

let y = Marshal.PtrToStructure(ptr,typeof<y>) :?> y 
y.t (* = true *)


Create a new paste based on this one


Comments: