From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 72A0BBC69 for ; Sat, 24 Feb 2007 11:52:55 +0100 (CET) Received: from furbychan.cocan.org (furbychan.cocan.org [80.68.91.176]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1OAqrRB028834 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Sat, 24 Feb 2007 11:52:55 +0100 Received: from rich by furbychan.cocan.org with local (Exim 3.35 #1 (Debian)) id 1HKuWI-0006GQ-00; Sat, 24 Feb 2007 10:52:50 +0000 Date: Sat, 24 Feb 2007 10:52:50 +0000 To: micha Cc: caml-list@inria.fr Subject: Re: [Caml-list] coding c++ enum type Message-ID: <20070224105250.GA24014@furbychan.cocan.org> References: <45E00103.9020809@fantasymail.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <45E00103.9020809@fantasymail.de> User-Agent: Mutt/1.5.9i From: Richard Jones X-Miltered: at discorde with ID 45E01905.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; enum:01 0100,:01 interfacing:01 flags:01 variants:01 flags:01 initialized:01 camlcvs:01 cvsweb:01 ocaml:01 otherlibs:01 camlcvs:01 cvsweb:01 ocaml:01 byterun:01 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: http://camlcvs.inria.fr/cgi-bin/cvsweb/ocaml/otherlibs/unix/open.c?rev=1.8.2.3;content-type=text%2Fx-cvsweb-markup (actually, convert_flag_list: http://camlcvs.inria.fr/cgi-bin/cvsweb/ocaml/byterun/alloc.c?rev=1.29;content-type=text%2Fx-cvsweb-markup ) Rich. -- Richard Jones Red Hat UK Limited