Thanks a lot Jeremy for your answer! I have chosen to write helper C functions to access the records containing bitfields, so that I let the compiler do its business without caring too much. I guess that no field after a bitfield definition in a struct can be reliably accessed either (with ctypes), even if it's not a bitfield itself (as there is no means to know if the bitfield was packed or padded). Is that right?
2014-05-17 2:14 GMT+02:00 Jeremy Yallop <[email protected]>: > Dear Philippe, > > On 16/05/2014, Philippe Veber <[email protected]> wrote: > > Has ctypes some support for bit fields in C struct? > > Not yet, I'm afraid. > > > If not is it correct to > > encode: > > > > typedef struct { > > int32_t pos; > > uint32_t bin:16, qual:8, l_qname:8; > > ... > > } bam1_core_t > > > > as: > > > > type bam1_core_t > > let bam1_core_t : bam1_core_t structure typ = structure "bam1_core_t" > > let bam1_core_t_pos_f = field bam1_core_t "pos" int32_t > > let bam1_core_t_props_f = field bam1_core_t "props" int32_t > > ... > > let () = seal bam1_core_t > > > > and then play with the fake "props" field directly? > > It's quite likely to work but it's not guaranteed, since the C > standard gives compilers a fair amount of freedom in laying out > bit-fields. The good news is that the standard also requires > compilers to document how bit-fields are laid out, so your compiler > documentation may have helpful details. > > Kind regards, > > Jeremy. >
_______________________________________________ Ctypes mailing list [email protected] http://lists.ocaml.org/listinfo/ctypes
