[cairo] const usage in API

Carl Worth cworth at cworth.org
Fri Nov 9 14:10:49 PST 2007


On Fri, 09 Nov 2007 23:59:16 +0200, Hakki Dogusan wrote:
> Some functions use const for parameters, but some not. Is there a rule?

Yes.

> cairo_public void
> cairo_scaled_font_extents (cairo_scaled_font_t  *scaled_font,
>       	cairo_font_extents_t *extents);
>
> cairo_public void
> cairo_set_matrix (cairo_t *cr,
> 	const cairo_matrix_t *matrix);

In the case of cairo_scaled_font_extents, that function is *writing*
to the extents structure you pass in, (definitely not const).

In the case of cairo_set_matrix, that function is only *reading* from
the matrix you pass in---the const guarantees that it will not be
modified.

For things like the cairo_scaled_font_t* and cairo_t*, those are
opaque data types. The user of the API can't look inside them so can't
care if the structures will be modified or not.

-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20071109/28ba1bcf/attachment.pgp 


More information about the cairo mailing list