Looking to compare two
BYTE PhysicalAddress[MAX_ADAPTER_ADDRESS_LENGTH];
from the IP_ADAPTER_ADDRESSES Structure
where byte is defined in windows as typedef unsigned char BYTE;
Do I need to compare memory?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Matteo beat me to it. His answer is correct. Unfortunately I could not comment directly on his post (I may be too new here), but I wanted to confirm his response since the majority of answers thus far are incorrect.
The data type in question is an array of bytes.
Do NOT use the equality operator (==) for comparing the values of two arrays, it will only evaluate to true if you’re comparing the same array to itself. Even if the byte arrays have the same values across each of their elements, yet are different arrays (and therefore reside at different places in memory), the equality operator will return false.
In essence, an array is just a pointer in memory. Here are two ways to declare arrays:
or:
You can access the first element with either:
or:
You can even do:
or:
This should demonstrate that an ‘array’ is just a pointer to the first element of a block of contiguous memory. So, when comparing two arrays to eachother using the equality operator, it’s the same as comparing two pointers to eachother. To re-iterate the main point, if the arrays are not in the same space in memory, the pointers point to different places, and are therefore not ‘equal,’ at least in terms of the equality operator.
I hope this is appropriate information for your skill level 🙂 If not, perhaps it will help someone else. Also, it’s been a while since I’ve had the pleasure of using C++, so hopefully everything is correct.