[cairo] const usage in API

Jonathon Jongsma jonathon at quotidian.org
Fri Nov 9 14:07:34 PST 2007

On 11/9/07, Hakki Dogusan <dogusanh at tr.net> wrote:
> Hi,
> Some functions use const for parameters, but some not. Is there a rule?
> ex:
> 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);

Well, in these particular examples, there is a good reason for the
difference.  cairo_scaled_font_extents() is an accessor function.  The
'extents' parameter is an output parameter, so it can't be const.
In cairo_set_matrix(), the matrix param is an input-only parameter
that won't be changed so it can be const.
There might be other functions that don't use const consistently, but
in this specific case there's a good reason for the difference.


More information about the cairo mailing list