[cairo] return type of cairo_status_to_string ()

Tor Lillqvist tml at iki.fi
Wed Aug 18 02:20:32 PDT 2010


> I still can't imagine why someone would try to modify the string, such as char
> *error_str = func (); error_str [0] = 'x';

That was just an example, and as such exactly that is not something
anybody would likely do. But I can well imagine somebody wanting (for
some silly reason) to make an error message all lower case, for
instance. Or truncating the error message after n chars and adding
"...". Or something...

Note that using "const" here does not "guarantee" that the string
won't be altered. It is after all C we are talking about, and one can
use casts. (And not all implementations necessarily store string
literals (assuming here that we "know" the return value is in fact
pointing to a string literal, and not just any char array) in
write-protected memory.) But it makes it less likely to do it
unintentionally.

--tml


More information about the cairo mailing list