[cairo] Missing const in cairo API ?
Behdad Esfahbod
behdad at behdad.org
Sun Oct 1 17:31:09 PDT 2006
On Sun, 2006-10-01 at 17:43 -0400, Damien Carbonne wrote:
> Hello,
>
> I'm new to this list. I'm presently trying to write an Ada binding to
> Cairo and have some questions about usage of const in C API. Sorry if
> this has already been asked in this list.
> I'll give two examples :
>
> cairo_public void
> cairo_scaled_font_extents (cairo_scaled_font_t *scaled_font,
> cairo_font_extents_t
> *extents);
>
> cairo_public cairo_status_t
> cairo_font_face_status (cairo_font_face_t *font_face);
>
>
> Why aren't they defined as :
> cairo_public void
> cairo_scaled_font_get_extents (const cairo_scaled_font_t *scaled_font,
>
> cairo_font_extents_t *extents);
>
> cairo_public cairo_status_t
> cairo_font_face_get_status (const cairo_font_face_t *font_face);
>
> From documentation, it would seem legitimate to believe that such
> functions should not modify scaled font or font face objects.
> When reading cairomm API, I've the feeling they sometimes make the same
> assumption, using const_cast.
>From the user's point of view, yes, they should be const. But
implementation-wise, not. For example, caches may be created for them
on demand, or various other internal changes made to them.
However both scaled_font_t and font_face_t objects are immutable, so, by
definition any operation on them is constant with that meaning.
And I'm not sure if adding const keywords in the API is even safe. The
compiler uses consts to make certain assumptions. Can't think of
anything in particular here though.
--
behdad
http://behdad.org/
"Commandment Three says Do Not Kill, Amendment Two says Blood Will Spill"
-- Dan Bern, "New American Language"
More information about the cairo
mailing list