[Gdal-dev] build error using Visual Studio 8

Mateusz Łoskot mateusz at loskot.net
Sun Apr 2 11:12:21 EDT 2006


Frank Warmerdam wrote:
> Bart van den Eijnden (OSGIS) wrote:
>> Hi guys,
>> 
>> using the CVS version of GDAL which comes from the Mapserver 
>> Windows buildkit (31 March 2006?), I get the following problem 
>> compiling with Visual Studio 8:
>> 
>> cpl_strtod.cpp cpl_strtod.cpp(444) : error C2440: '=' : cannot 
>> convert from 'const char *' to ' char *' Conversion loses 
>> qualifiers
> 
> Bart,
> 
> I have committed a chance casting the return result to char *.
> 
> p = (char *) strchr (hexits, tolower (*sc));

Hi Frank,

The problem is because ISO C++ does not provide C version of strchr.
C++ version solves limitations of C language, so that's why ISO C++
provides slightly different versions of strchr.

Here is how does it look like regarding C/C++ standards

char *strchr(const char *s, int c); [not in C++]

const char *strchr(const char *s, int c); [C++ only]
char *strchr(char *s, int c); [C++ only]

So, in C++, returning non-const char* from const char* brokes const
corretness. So, it maybe unsafe to use that cast (char*)strchr(...).

Second problem is that the C version of strchr is "visible" from g++
compiler, but that's unstandard and is caused by well-known bug in
GCC/libstdc++. So, the problem with strchr occurs in VC++ which compiler
is to be free of this bug.

Third, VC++ is not a C compiler but C++ - that's what I've heared from
Microsfot gurus ;-) So, VC++ does not support buggy mixtures of C/C++
libraries/features.

Here is longer story I started onb libstdc++ mailing list:
http://gcc.gnu.org/ml/libstdc++/2006-02/msg00086.html

The question is how GDAL should handle it. Should GDAL behave more in C
way or more in C++ way?


Cheers
-- 
Mateusz Łoskot
http://mateusz.loskot.net



More information about the Gdal-dev mailing list