Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
MEMCMP simply compares the memory bits between two locations. This has nothing to do with whatever those bits might mean. Your first example, on the other hand, compares the contents of variable ...
Answer
#2: Post edited
- MEMCMP simply compares the memory bits between two locations. This has nothing to do with whatever those bits might mean.
Your first example, on the other hand, compares the contents of variable X with the value 0. Doing a MEMCMP with an area of memory with all bits 0 is the same thing, <i>only if you know the representation the value 0 in X is all bits 0</i>.The distinction becomes more obvious when using a value other than 0. Let's say you know X is a 32 bit integer and you want to check whether its value is 7. The expression (x == 7) will always work, since it's directly asking what you want to know. It does not suppose a particular representation for the value 7. Using MEMCMP, do you compare the bits of X with byte sequence 00 00 00 07, or 07 00 00 00? Both are quite possible on common modern machines. The difference in this example is whether the machine uses little or big endian.- I used endianess as an example only. There are other possible reasons that make this kind of use of MEMCMP machine and possibly compiler specific. For example, the representation of 1.0 in a common 32 bit floating point format is 3F800000h. And that's only the value of the raw bits expressed as a 32 bit integer. Endianess still applies.
- MEMCMP simply compares the memory bits between two locations. This has nothing to do with whatever those bits might mean.
- Your first example, on the other hand, compares the contents of variable X with the value 0. Doing a MEMCMP with an area of memory with all bits 0 is the same thing, <i>only if you know the representation of the value 0 in X is all bits 0</i>.
- The distinction becomes more obvious when using a value other than 0. Let's say you know X is a 32 bit integer and you want to check whether its value is 7. The expression (x == 7) will always work, since it's directly asking what you want to know. It does not suppose a particular representation for the value 7. Using MEMCMP, do you compare the bits of X with the byte sequence 00 00 00 07, or 07 00 00 00? Both are quite possible on common modern machines. The difference in this example is whether the machine is little or big endian.
- I used endianess as an example only. There are other possible reasons that make this kind of use of MEMCMP machine and possibly compiler specific. For example, the representation of 1.0 in a common 32 bit floating point format is 3F800000h. And that's only the value of the raw bits expressed as a 32 bit integer. Endianess still applies.
#1: Initial revision
MEMCMP simply compares the memory bits between two locations. This has nothing to do with whatever those bits might mean. Your first example, on the other hand, compares the contents of variable X with the value 0. Doing a MEMCMP with an area of memory with all bits 0 is the same thing, <i>only if you know the representation the value 0 in X is all bits 0</i>. The distinction becomes more obvious when using a value other than 0. Let's say you know X is a 32 bit integer and you want to check whether its value is 7. The expression (x == 7) will always work, since it's directly asking what you want to know. It does not suppose a particular representation for the value 7. Using MEMCMP, do you compare the bits of X with byte sequence 00 00 00 07, or 07 00 00 00? Both are quite possible on common modern machines. The difference in this example is whether the machine uses little or big endian. I used endianess as an example only. There are other possible reasons that make this kind of use of MEMCMP machine and possibly compiler specific. For example, the representation of 1.0 in a common 32 bit floating point format is 3F800000h. And that's only the value of the raw bits expressed as a 32 bit integer. Endianess still applies.