[geos-devel] Pedantic build of GEOS
Mateusz Łoskot
mateusz at loskot.net
Tue Mar 21 06:17:43 EST 2006
strk at refractions.net wrote:
> By building with -pedantic on I get warnings about the use of 'long
> long'.
I attached report with complete output from my try.
> Do you have suggestion as how to change it to a standard name ?
AFAIK there is no standard way to solve the problem.
C99 and gcc provides support of 64 integral type as long long.
Microsoft VC++ supports it too in form of type named as __int64.
So, I think the only solution is to wrap it in #ifdef's and typedef's.
Here is some example of possible header I found on
comp.lang.c++, author: Eyal Ben-David.
This header wraps integral types in multiplatform way, so I think
similar solution will suffice:
/---------------------------------------------------
//
// Note 1:
// we can replace CHAR_BIT with C++ header <limits> and the member
// function digits(), but G++ does'n have it (yet)
//
// Note 2:
// I needed the preprocessor for conditional compilation because I
// wanted to support non standard types such as __int64 or long long
//
#include <limits.h>
namespace Int_Types {
#if defined (_WIN32) && (defined(__BORLANDC__) || defined (_MSC_VER))
typedef __int64 LONG_LONG;
typedef __int64 U_LONG_LONG;
typedef __int64 S_LONG_LONG;
#endif
#if defined (__GNUG__)
typedef long long LONG_LONG;
typedef signed long long S_LONG_LONG;
typedef unsigned long long U_LONG_LONG;
#endif
template <int N> struct IntTypeHelper
{
};
template<> struct IntTypeHelper<0>
{
typedef char type;
typedef signed char signed_type;
typedef unsigned char unsigned_type;
};
template<> struct IntTypeHelper<1>
{
typedef short type;
typedef signed short signed_type;
typedef unsigned short unsigned_type;
};
template<> struct IntTypeHelper<2>
{
typedef int type;
typedef signed int signed_type;
typedef unsigned int unsigned_type;
};
template<> struct IntTypeHelper<3>
{
typedef long type;
typedef signed long signed_type;
typedef unsigned long unsigned_type;
};
template<> struct IntTypeHelper<4>
{
typedef LONG_LONG type;
typedef S_LONG_LONG signed_type;
typedef U_LONG_LONG unsigned_type;
};
template <int N> class IntType
{
private:
enum
{
value =
(N > (sizeof(char) * CHAR_BIT)) +
(N > (sizeof(short)* CHAR_BIT)) +
(N > (sizeof(int) * CHAR_BIT)) +
(N > (sizeof(long) * CHAR_BIT)) +
(N > (sizeof(LONG_LONG) * CHAR_BIT))
};
public:
typedef typename IntTypeHelper<value>::type type;
typedef typename IntTypeHelper<value>::signed_type signed_type;
typedef typename IntTypeHelper<value>::unsigned_type unsigned_type;
};
// declare some common typedefs.
//
typedef IntType<8>::type int8;
typedef IntType<8>::signed_type sint8;
typedef IntType<8>::unsigned_type uint8;
typedef IntType<16>::type int16;
typedef IntType<16>::signed_type sint16;
typedef IntType<16>::unsigned_type uint16;
typedef IntType<32>::type int32;
typedef IntType<32>::signed_type sint32;
typedef IntType<32>::unsigned_type uint32;
typedef IntType<64>::type int64;
typedef IntType<64>::signed_type sint64;
typedef IntType<64>::unsigned_type uint64;
} // namespace Int_Types
#ifdef TEST
#include <iostream>
#include <typeinfo>
int main()
{
using namespace std;
using namespace Int_Types;
// uncomment to see ...
//cout << typeid( IntType<65>::unsigned_type).name() << "\n";
cout << typeid( IntType<5>::type).name() << ", "
<< typeid( IntType<10>::type).name() << ", "
<< typeid( IntType<20>::type).name() << ", "
<< typeid( IntType<33>::type).name() << "\n";
cout << "int 8:\t"
<< typeid(int8).name() << ", "
<< typeid(sint8).name() << ", "
<< typeid(uint8).name() << endl;
cout << "int 16:\t"
<< typeid(int16).name() << ", "
<< typeid(sint16).name() << ", "
<< typeid(uint16).name() << endl;
cout << "int 32:\t"
<< typeid(int32).name() << ", "
<< typeid(sint32).name() << ", "
<< typeid(uint32).name() << endl;
cout << "int 64:\t"
<< typeid(int64).name() << ", "
<< typeid(sint64).name() << ", "
<< typeid(uint64).name() << endl;
}
#endif // TEST
//------------------------------------------------------------
>
> About virtual destructor I agree we should fix that. Patches welcome.
>
OK. I've assigned myself to this bug. I'll fix it this week.
Cheers
--
Mateusz Łoskot
http://mateusz.loskot.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: geos-pedantic-warnings.tar.gz
Type: application/x-gzip
Size: 13330 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/geos-devel/attachments/20060321/11c86815/geos-pedantic-warnings.tar.gz
More information about the geos-devel
mailing list