[cairo] Adding a boolean type

Owen Taylor otaylor at redhat.com
Tue Feb 1 06:24:02 PST 2005


On Tue, 2005-02-01 at 09:15 -0500, Carl Worth wrote:
> On Mon, 31 Jan 2005 19:02:45 -0500, Owen Taylor wrote:
> > What if we add:
> > 
> >  typedef char cairo_bool_t;
> >  #define CAIRO_FALSE 0
> >  #define CAIRO_TRUE  1
> 
> Where do you propose adding these? The cairo_bool_t would be useful in
> the public header to make the behavior of any predicates more
> apparent, (I think cairo_in_stroke and cairo_in_fill are all we have
> so far). But it doesn't necessarily follow that the TRUE/FALSE defines
> need also be public. They're certainly never useful for testing return
> values from functions, (only in generating those values).

As you say, we currently don't have many instances in the public
interfaces and no places where we'd need to use #defines in 
example code.

But not adding some sort of public TRUE/FALSE defines publically 
seems sort of a half-measure. And are we going to remember to add
the defines if we add a usage of cairo_bool_t as a parameter?

We need #defines at least for examples if we have cairo_bool_t 
parameters, because while most people are going to have true/false
(stdbool.h, C++) FALSE/TRUE (GLib, Windows) or True/False (Xlib)
available, we can't use any of them in examples.

> >  char vs. int: For Glib we picked int, to reduce the risk of
> >    'GBoolean bool = flags & FLAG' traps, but mostly it doesn't matter,
> >    and char seems to be more common in general.
> 
> That's a scary trap. 

It's a nasty trap, though writing (flags & FLAG) != 0 is pretty
essential anyways. The only way to get around that need is to have
a language extension like C99 _Bool.

> What are the arguments in favor of char? I can't
> think of any real ones, and I haven't seen any in this thread.

I think mostly that it packs tighter for arrays of boolean and
in structures (where bitfields aren't used.)

> My inclination would be:
> 
> cairo.h:
> 	typedef int cairo_bool_t;
> 
> cairoint.h:
> 	#define FALSE 0
> 	#define TRUE  1

Would defining TRUE/FALSE in cairoint.h and CAIRO_TRUE/CAIRO_FALSE
in cairo.h make sense? Or is it just complicating things?

Regards,
						Owen

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050201/54eb688d/attachment.pgp


More information about the cairo mailing list