ocamllabs/ocaml-ctypes — pull request #30 by yallop (2013-07-01 10:44:20+00:00)
Title: Obtain struct layout details from C to help avoid runtime mismatches.

# module V = Verify_struct_layout
[...]
# V.struct_info ~headers:["sys/types.h"] ~tag:"timeval"
~fields:["tv_sec"; "tv_usec"];;
- : V.struct_info =
{V.tag = "timeval";
fields =
[{V.label = "tv_sec"; offset = 0; size = 8};
{V.label = "tv_usec"; offset = 8; size = 8}];
size = 16}
# V.struct_info ~headers:["time.h"] ~tag:"tm"
~fields:["tm_isdst"; "tm_mday"; "tm_mon"; "tm_year";
"tm_wday"; "tm_yday"; "tm_sec"; "tm_min"; "tm_hour"];;
- : V.struct_info =
{V.tag = "tm";
fields =
[{V.label = "tm_sec"; offset = 0; size = 4};
{V.label = "tm_min"; offset = 4; size = 4};
{V.label = "tm_hour"; offset = 8; size = 4};
{V.label = "tm_mday"; offset = 12; size = 4};
{V.label = "tm_mon"; offset = 16; size = 4};
{V.label = "tm_year"; offset = 20; size = 4};
{V.label = "tm_wday"; offset = 24; size = 4};
{V.label = "tm_yday"; offset = 28; size = 4};
{V.label = "tm_isdst"; offset = 32; size = 4}];
size = 56}

Currently just a comically inefficient proof-of-concept implementation.