[Bf-committers] Casting arrays (matrices)
Wed, 2 Jul 2003 17:01:06 -0400 (EDT)
I'm with Maarten on this one. If I gave you a prototype for a string copy
function that read "strcyp(char *target,const char *source)" it would not
only tell you that your source string wouldn't be modified, but it would
allow the compiler to enforce that behavior.
The "const" modifier is a great documentation feature, at the very
minimum, and provides an additional level of protection from coding errors
at best. Incidentally, it also helps the optimizer.
On Wed, 2 Jul 2003, Maarten Gribnau wrote:
> Hi Ton
> > Reading the arithb.c code, I found that someone (NaN) has included a
> > lot of 'const' variables in the function declarations. I have
> > absolutely no clue what it's good for. Originally, the code worked
> > fine without, as still is in the MTC_matrixops.c version in
> > source/blender/blenlib/
> > I've removed the 'const' everywhere from arithb.c. The code compiles
> > quite a lot faster, with only a few and more useful warnings left.
> How does the const cause trouble?
> The const is actually useful. It tells you the function is not going to
> modify the variable (usually pointers and references in C++) passed to
> it. It makes the variable an "in only" variable.