English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2007-02-24 (10:52)
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:


(actually, convert_flag_list:
http://camlcvs.inria.fr/cgi-bin/cvsweb/ocaml/byterun/alloc.c?rev=1.29;content-type=text%2Fx-cvsweb-markup )


Richard Jones
Red Hat UK Limited