Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
coding c++ enum type
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] coding c++ enum type
On Sat, Feb 24, 2007 at 10:10:27AM +0100, micha wrote:
> when interfacing to c, what is the preferred method to represent enums 
> which are used as flags in c?
> I can choose between:
> 1. using a variant type and  a list of those variants to represent the 
> or-ed flags. Then I have to iterate over the list to calculate the 
> combined flag value.
> 2. I can export global variables initialized with the real value of the 
> flags and a function which combines  (with "or") them together,
> Is one method better than the other?

I don't know about preferred, but most libraries seem to be using the
list approach (1).  See for example to source to Unix.openfile:;content-type=text%2Fx-cvsweb-markup

(actually, convert_flag_list:;content-type=text%2Fx-cvsweb-markup )


Richard Jones
Red Hat UK Limited