[cairo] return type of cairo_status_to_string ()

M Joonas Pihlaja jpihlaja at cc.helsinki.fi
Tue Aug 17 15:34:28 PDT 2010


On Tue, 17 Aug 2010, Daniel Goldman wrote:

> What bad thing does the const keyword prevent here? If nothing bad prevented, 
> then I think it should be the simpler, more default "char *".

In C, returning a const char * from a function tells the caller that 
they do not need to call free() on the returned address to reclaim 
storage.  When returning a char *, the caller needs to worry about 
ownership of the returned storage and go read docs to find out what 
the policy is.

> I'm not expecting a detailed off-topic discussion about the const keyword. I 
> would just like a real-world example showing the purpose for this particular 
> function.

Mostly when debugging it's useful to see what the human readable 
status is like this:

/* ... at the end of rendering ... */
status = cairo_status(cr);
if (status != CAIRO_STATUS_SUCCESS) {
	fprintf(stderr, "eek!  error '%s' while rendering\n",
		cairo_status_to_string(status));
}

Cheers,

Joonas


More information about the cairo mailing list