Skip to content

Instantly share code, notes, and snippets.

@sayurin
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sayurin/9108129 to your computer and use it in GitHub Desktop.
Save sayurin/9108129 to your computer and use it in GitHub Desktop.
#nowarn "9"
open System.Runtime.InteropServices
[<Struct; StructLayout(LayoutKind.Explicit)>]
type s =
[<DefaultValue; FieldOffset 0>]
val mutable y : uint32
[<DefaultValue; FieldOffset 0>]
val mutable x1 : byte
[<DefaultValue; FieldOffset 1>]
val mutable x2 : byte
[<DefaultValue; FieldOffset 2>]
val mutable x3 : byte
[<DefaultValue; FieldOffset 3>]
val mutable x4 : byte
do
let t = s(x1 = 1uy, x2 = 2uy, x3 = 3uy, x4 = 4uy)
printfn "%x" t.y
do
let t = s(y = 0x01020304u)
printfn "%x %x %x %x" t.x1 t.x2 t.x3 t.x4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment