[cairo] const usage in API

Hakki Dogusan dogusanh at tr.net
Fri Nov 9 14:33:38 PST 2007


Hi,

Jonathon Jongsma wrote:

Thanks for reply.

> 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.
> 


But, why "scaled_font" parameter doesn't use const?


ps. seeing a const helps me to generate/check lua binding without 
consulting to the docs. Since lua has not pointers, I'm emulating them 
with returned values.ie:

C:    void a(int *p1, int *p2, const int *p3);
Lua: p1,p2 = a(p1, p2, p3)


--
Regards,
Hakki Dogusan


More information about the cairo mailing list