From: "Nathaniel Gray" <n8gray@gmail.com>
To: micha <micha-1@fantasymail.de>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] coding c++ enum type
Date: Sat, 24 Feb 2007 13:33:10 -0800 [thread overview]
Message-ID: <aee06c9e0702241333k3c14b5f6x67730c6796adeac3@mail.gmail.com> (raw)
In-Reply-To: <45E00103.9020809@fantasymail.de>
On 2/24/07, micha <micha-1@fantasymail.de> 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?
The Unix library uses both techniques -- using a single int for file
permissions but a list of flags in various other cases.
Personally, I think that as long as the bitfield fits in 31 bits then
it's better to keep it as a simple int. Bitfields allow you to do
some things very simply that would be more painful with a list of
constructors. For example, testing if flags a, b, and c are set can
be done very quickly and easily with a bitfield, but becomes somewhat
laborious and/or slow with lists. You can easily provide an
additional "list of variants" interface on the ML side if you think
some users would prefer that.
Cheers,
-n8
--
>>>-- Nathaniel Gray -- Caltech Computer Science ------>
>>>-- Mojave Project -- http://mojave.cs.caltech.edu -->
prev parent reply other threads:[~2007-02-24 21:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-24 9:10 micha
2007-02-24 10:52 ` [Caml-list] " Richard Jones
2007-02-24 21:33 ` Nathaniel Gray [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aee06c9e0702241333k3c14b5f6x67730c6796adeac3@mail.gmail.com \
--to=n8gray@gmail.com \
--cc=caml-list@inria.fr \
--cc=micha-1@fantasymail.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox