[vtk-developers] (Another) bug in MS Visual Studio

Andy Cedilnik andy.cedilnik at kitware.com
Thu May 30 09:30:57 EDT 2002


Here is an example:

void DoSomething(char * s) { 
  // do something with string
}

void DoSomething(const char* s) {
  // Make a copy of string s
  // do something with a copy
}

Why would you do this?
Well, for example Tcl_GlobalEval takes char* and it actually modifies
it. So, if you say Tcl_GlobalEval(interp, "something") will crash. Well,
I guess that is a Tcl bug, but still... "something" is associated with a
piece of memory, but this memory is read only. If you try to change it
you are in trouble.

				Andy

On Thu, 2002-05-30 at 09:03, Miller, James V (Research) wrote:
> I guess a side question is:
> 
> Why would you have two functions with the same name where one takes 
> a const and the other does not AND the two functions perform DIFFERENT
> operations?
> 
> While this is probably a bug for at least some of the compilers (not willing
> to say which compilers are doing the correct thing), I would say it is
> also a bad design. A user should expect functions with the same name to 
> perform the same operation. When I need to provide const and non const
> versions of the same function, I usually have one call the other; but at 
> a minimum, I have them do the same thing.





More information about the vtk-developers mailing list