[ocaml-ctypes] C-array of fixed size, #defines and C11 anonymous unions

Markus Weißmann markus.weissmann at in.tum.de
Wed Feb 12 07:59:13 GMT 2014


Hello ctypes list,

1.) I was wondering how fixed-size C-arrays should be handled in 
ctypes;
there exist several APIs that use a fixed-size array as part of a 
struct, e.g. ifreq (used to configure network interfaces via ioctl(2) on 
linux)

struct ifreq {
   union {
     char ifrn_name[16];
   } ifr_ifrn;
...

How do I handle that in ctypes?


2.) Is there a "clever" way of handling C-#defines? One obvious 
possibility is to look them up manually and then hope that e.g. BUFSIZ 
is the same on all machines used;
another would be to introduce a stub.c file just to handle the 
#defines... defeating somehow the purpose of ctypes.
Something that would work, too, is to write a generator in C that 
creates a defines.ml for me (e.g. "printf("let bufsiz = %d\n", BUFSIZ))
Has someone found the holy grail (tm) for this problem?


3.) The C11 standard allows for unnamed unions -- not a concrete 
problem right now, but is there a more elegant way than to introduce a 
new name for the union in my ocaml/ctypes code?

typedef struct {
   union {
     float f;
     int i;
   };
} some_t;
...
some_t x;
x.f = 4.5;
printf("%d", x.i);


Best regards,

-Markus

-- 
Markus Weißmann, M.Sc.
Technische Universität München
Institut für Informatik
Boltzmannstr. 3
D-85748 Garching
Germany
http://wwwknoll.in.tum.de/



More information about the Ctypes mailing list