It's the strcmp implementation in 'C' and i am guessing the same implementation is passed onto C++.
Can anybody explain what is going on in the last line of code. I see that the return type of the function is 'int' so the code is somehow converting pointer to int but i don't understand how?
*(constunsignedchar*)s1
The (constunsignedchar*)s1 part basically means static_cast<constunsignedchar*>(s1)
So we have pointer to const unsigned char. You also see that before (constunsignedchar*)s1 there is one more * what means that we are dereferencing this pointer and getting just constunsignedchar what was pointed to by this pointer
Same thing happens with s2 and now we have just 2 constunsignedchars.
You can implicitly convert the difference between s1 and s2 what is constunsignedchar to int
EDIT : correct me if im wrong maybe (constunsignedchar*)s1
means reinterpret_cast<constunsignedchar*>(s1)
instead of static_cast<constunsignedchar*>(s1)
Remember, char is an integer type, so they can treated just like any other integer. Their only special quality is that they display differently than other kinds of integer.
Subtracting the two provides a negative value (s1 < s2), a positive value (s1 > s2), or zero (s1 == s2).
@etrusks
Neither; a c-style cast is an absolute, I'm smarter than the compiler, cast.