Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2005

Tip: Looking for answers? Try searching our database.

casting &Byte[] to long value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Carl - 30 Jun 2005 16:00 GMT
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]))
   { ... }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.