[vtkusers] Can't CMake configure VTK on C++ Builder XE2 compiler

James Johnston JamesJ at motionview3d.com
Fri Aug 31 16:05:20 EDT 2012


Hi,

I'm trying to use CMake to configure VTK 5.10.0 for the C++ Builder XE2
Update 4 compiler.  One of the test programs in VTK as part of the
"autoconf"-type sequence crashes; I traced the crash as follows:

VTK\Utilities\vtkhdf5\Resources\ConversionTests.c

#ifdef H5_FP_TO_ULLONG_RIGHT_MAXIMUM_TEST
int main(void)
{
  float f =        9701917572145405952.00f;
  double d1 =      9701917572145405952.00L;
  long double d2 = 9701917572145405952.00L;
  double d3 = 2e40L;
// THE FOLLOWING LINE CRASHES:
  unsigned long long l1 = (unsigned long long)f;

The crash seems to stem from the following:

1.  The float is attempted to be casted to an unsigned long long.  On GCC
4.5.3 the code works because "l1" stores the correct value of
"9701917980169863168".

2.  Unfortunately, it seems that the float is actually casted to a signed
long long (or some other similar funny business) before then being stored in
the unsigned variable.  This must be a compiler bug; I tested it and this
buggy behavior seems to be in both Visual C++ 2008 SP1 and C++ Builder XE2.
On VC++ 2008, "l1" stores "9223372036854775808" which seems to be the
absolute value of the minimum value that can be stored in a signed 64-bit
integer.

3.  Even more unfortunately, the entire program crashes on C++ Builder XE2.
That's because FPU exceptions are turned on by default in C++ Builder,
unlike Visual C++ which disables them by default.  So instead of getting an
incorrect result in "l1", the program just crashes, probably due to
"overflow" when erroneously converting to signed long long.

What's the best way to proceed?

Best regards,

James Johnston





More information about the vtkusers mailing list