[cairo] char* vs. unsigned char*

Carl Worth cworth at cworth.org
Mon Apr 4 07:42:03 PDT 2005

I recently started compiling cairo code with gcc 4 and I'm getting
lots of new warnings regarding the signedness of pointer
parameters. Things along the lines of:

warning: pointer targets in passing argument 4 of 'some_function' differ in signedness

A common source of these warnings is a mismatch between char* and
unsigned char*.

I spent a bit of time trying to shut the warnings up by propagating
signedness up from the various libraries that cairo uses, and down
from the existing cairo interfaces.

This was a rather frustrating experience since there are incompatible
interfaces that cairo uses making it impossible to solve the problem
without casts. For example, gstate->font_family is passed to
fontconfig's FcPatternAddString which expects an unsigned char*, but
gstate->font_family is also copied with libc's strdup which returns a

Now that I've grumbled a bit, I need to put the few necessary casts
in, and also decide which types cairo should export. So I'm looking
for recommendations as to which types we should have in the interface.

My inclination is that actual string data, (such as font->family), is
unlikely to see much arithmetic for which signedness should matter, so
we should probably use char* for that. That would give compatibility
with libc.

But data, such as in cairo_set_target_image may see arithmetic, so
perhaps it should be unsigned char*. That would give compatibility
with freetype, libpng, Xlib, and zlib which all expect unsigned char*

If anyone has alternate suggestions or compelling arguments for a
particular use case, please let me know.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050404/f26bf53b/attachment.pgp

More information about the cairo mailing list