Hi,
I have an array of bytes like
Byte m_Data[] = new Byte[2000] ;
Byte sequences starting at a random index (4 byte aligned) should be
interpreted as unsigned long values and compared with each other.
My first try was
if ( reinterpret_cast<UInt32*>(&m_Data[20]) ==
reinterpret_cast<UInt32*>(&m_Data[104]) )
{ ... }
but the results were not always as expected (guess due to the == operator
handling the pointers).
The second try was
__value UInt32* a = reinterpret_cast<__value UInt32*>(&m_Data[20] ) ;
__value UInt32* b = reinterpret_cast<__value UInt32*>(&m_Data[104]) ;
if ( *a == *b )
{ ... }
That seems to work, but I dislike the need of extra variables (due to
performance reasons).
Has someone a really good idea about that?
Thanks
Carl
Rob Haynes - 30 Jun 2005 16:48 GMT
In your first example, you are comparing two UInt32* pointers which should
never be equal. In the second example, you are getting the pointers and
then comparing what they point at, which seems more useful.
> Hi,
>
[quoted text clipped - 30 lines]
>
> Carl
Norman Diamond - 01 Jul 2005 03:40 GMT
> __value UInt32* a = reinterpret_cast<__value UInt32*>(&m_Data[20] ) ;
> __value UInt32* b = reinterpret_cast<__value UInt32*>(&m_Data[104]) ;
[quoted text clipped - 3 lines]
> That seems to work, but I dislike the need of extra variables (due to
> performance reasons).
if (*reinterpret_cast<__value UInt32*>(&m_Data[20]) ==
*reinterpret_cast<__value UInt32*>(&m_Data[104]))
{ ... }