Changing a function argument from T* to T const* will not
impact any C functions calling it. It also won’t impact
the function itself, unless of course the function is using
the pointer in a non-const way.
The change may impact C++, but only if this would result
in an ambiguous overload (which is very unlikely in this
context).
Unfortunately, there is a small snowball effect. The function
may be passing the pointer to a function which itself is
not correctly declaring an argument const that should be,
so that function will have to be modified as well.
Changing the return type of a function to T const*
may have a large snowball effect. It can break lots of
code which was forced to accept a T* previously, and
thus cannot accept a T const*. For example
int *id(int *pi) { return pi; }
int *p = &x; // some int x somewhere
int *q;
q = id(p);
Now if you change the argument to int const*, the function
return is wrong, so you have to make
int const *id(int const *pi) { return pi; }
And now
q = id(p); // ERROR assign int const* to int*q
The bottom line here is that changing pointers to use
const can snowball unless it is restricted to function
arguments.
The semantics of const are unfortunately not very useful:
the conversion T* --> T const* allows aliasing and thereby
make it impossible to cache pointed at values on the assumption
that they cannot change, which basically defeats its purpose.On Fri, 2006-03-31 at 17:18 -0500, Stea Greene wrote:
On Fri, Mar 31, 2006 at 01:56:49PM -0800, John Giors wrote:
Obviously, “const” would work fine in this case. Maybe you should try to
contact the SDL_ttf author. You might even download the source and take a
crack at the changes yourself…
That was my plan. If nobody did it for me, and nobody say “no, it will
misalign the whole planet if you did that”, my next step was to post a
patch. I’ll do that this weekend.
–
John Skaller
Felix, successor to C++: http://felix.sf.net