[cairo] return type of cairo_status_to_string ()

Behdad Esfahbod behdad at behdad.org
Wed Aug 18 10:03:38 PDT 2010


On 08/18/10 01:33, Daniel Goldman wrote:

> I still can't imagine why someone would try to modify the string, such as char 
> *error_str = func (); error_str [0] = 'x'; so the precaution in this case seems 
> unnecessary. I'm used to taking responsibility and not having the software 
> needlessly babysit me. But I've already adapted and moved on and learned some. 
> Uncle!!!

You can go read the docs for every function you want to use to see who owns
the return string, or you can just check the signature and know immediately
that it's owned by the library because it's const.  Or better yet, just use it
as you wish and the compiler will nag if you are not supposed to use it that way.

It's not just about convenience though.  The API is a contract: "you pass me a
valid cairo_status_t value, I pass you a valid const char *".  If it was
returning "char *" it meant "I'm returning you a string that you can modify if
you want to".

behdad


More information about the cairo mailing list