List:Internals« Previous MessageNext Message »
From:Sasha Pachev Date:December 4 2000 6:58pm
Subject:Re: Patch for SunPro CC 5.0
View as plain text  
d
>> Thanks for the patch - it is actually more correct to have * as const 
char* 
>> since table_name is const char*. However, SunPro CC is wrong in returning 
>> const char* from strchr() - it is a bug. The following legitimate code 
will 
>> not work without forcing type casts, for example:
>> 
>> char *p;
>> ...// initialize p
>> 
>> p = strchr(p, '.');
>> *p = 0;
>> 
>> One may want to tinker with the contents of the location that strchr() 
>> returned, so it should not be const. I guess their idea for making it 
const 
>> char* was that if you pass const char*, and return non-const this can 
bypass 
>> const correctness without a type cast.
>
>Hm. I may be completely wrong, but what if they have defined two
>versions of strchr(), one being const, the other one not. AFAIK, the
>compiler then chooses the const version before the non-const whenenver
>it can. This would make your example work nevertheless, Sasha.
>
>I haven't used this with global functions yet, but it works fine for
>member functions. One could check if they have done this by casting
>dot to char * before passing it to strchr().

This would be possible if strchr() was a pure C++ function. However, in 
strict C function overloading is not allowed, so they would have to 
distinguish with an #ifdef __cplusplus in the header file. Of course, a grep 
though the header files for strchr will resolve all doubts.


-- 
MySQL Development Team
   __  ___     ___ ____  __ 
  /  |/  /_ __/ __/ __ \/ /   Sasha Pachev <sasha@stripped>
 / /|_/ / // /\ \/ /_/ / /__  MySQL AB, http://www.mysql.com/
/_/  /_/\_, /___/\___\_\___/  Provo, Utah, USA
       <___/                  
Thread
Patch for SunPro CC 5.0Zow" Terry Brugger2 Dec
  • Re: Patch for SunPro CC 5.0Sasha Pachev2 Dec
    • Re: Patch for SunPro CC 5.0Benjamin Pflugmann3 Dec
      • Re: Patch for SunPro CC 5.0Sasha Pachev4 Dec
Re: Patch for SunPro CC 5.0Zow" Terry Brugger4 Dec