[Insight-users] FixedArray::operator[] definition for "unsigned __int64"

Ramón Casero Cañas rcasero at gmail.com
Wed Jul 20 13:55:16 EDT 2011


On 14/07/11 22:56, Bradley Lowekamp wrote:
> Hello Ramon,
>
> Which version of the Visual Studio compiler are you using?


Hi Brad,

Thanks for your reply. I'm using Visual Studio 10.

> It appears that you are relying on some type of implicit conversion. On
> may compilers this would produce a warning in some cases. It is best to
> make an explicit cast. My first guest would be to try the following, if
> you would like to to work on v3.20 and v4
>
> fixedPoint[col] = y[ static_cast<size_t>( Mx*col+row )];
>
> for just v4 you could also do:
>
> fixedPoint[col] = y[ static_cast<itk::SizeValueType>( Mx*col+row )];
>
> where itk::SizeValueType is defined in itkIntTypes.h, but should be
> indirectly included with just about any other itk header.


Actually, the implicit casting that gives the error is happening with 
col in fixedPoint[col] (thanks to Yves Martelli).

In principle, explicit casting would mean doing

   fixedPoint[static_cast<mwSize>(col)] = y[Mx*col+row];

but this wouldn't work in Windows 64 bit for ITK v3.20 because 
itkFixedArray.h doesn't have the following lines:

<CODE>
   reference operator[](unsigned long long index)        { return
m_InternalArray[index]; }
    const_reference operator[](unsigned long long index) const  { return
m_InternalArray[index]; }
</CODE>

Those lines are in ITK v4.0, so it should work for Windows 64 bit and 
ITK v4.0.


So the only solution that works with ITK v3.20 is defining a C macro 
(thanks to Jonathan Cooper) that will only cast to a smaller type in 
Windows 64 bit, e.g.

<CODE>
#ifdef _WIN64
#define CAST2MWSIZE(x) static_cast<unsigned long>(x)
#else
#define CAST2MWSIZE(x) static_cast<mwSize>(x)
#endif
</CODE>


Best regards,

Ramon.

-- 
Dr. Ramón Casero Cañas

Computational Biology
Department of Computer Science
University of Oxford
Wolfson Building, Parks Rd
Oxford OX1 3QD

tlf     +44 (0) 1865 610737
web     http://web.comlab.ox.ac.uk/people/Ramon.CaseroCanas
photos  http://www.flickr.com/photos/rcasero/


More information about the Insight-users mailing list