[vtk-developers] const correctness

Sean McBride sean at rogue-research.com
Thu Feb 10 15:21:29 EST 2011


On Thu, 10 Feb 2011 13:05:24 -0700, David Gobbi said:

>> From my perspective, as a client of VTK's public API, the advantage is
>> that sometimes I have something that really is const, say a const string
>> like "foo", and I need to pass it to a VTK API that takes char*.  If VTK
>> mutates the buffer I've passed, I'll crash. If it doesn't mutate, I'm
>> ok, but the compiler will rightly complain that I'm implicitly casting
>> away constness.
>
>This is something that I agree with 100%.  All "char *" parameters
>should be changed to take "const char *" unless they are intended to
>modify the string.

Not just char* of course, but they're probably most important, since
it's easy to have non-mutable string buffers.  For a non-char example, a
few weeks ago I fixed vtkMatrix4x4:

<http://vtk.org/gitweb?p=VTK.git;a=co
mmitdiff;h=790ee071450a4b1ae3372d4b2ec04f2acd7b328d>

-- 
____________________________________________________________
Sean McBride, B. Eng                 sean at rogue-research.com
Rogue Research                        www.rogue-research.com 
Mac Software Developer              Montréal, Québec, Canada





More information about the vtk-developers mailing list