The Windows SDK functions the IsEqualGUID () function and operator==() for two GUIDs that return BOOL (equivalent to int ):
// Guiddef.h #ifdef __cplusplus __inline int IsEqualGUID(REFGUID rguid1, REFGUID rguid2) { return !memcmp(&rguid1, &rguid2, sizeof(GUID)); } #else // ! __cplusplus #define IsEqualGUID(rguid1, rguid2) (!memcmp(rguid1, rguid2, sizeof(GUID))) #endif //also in Guiidef.h #ifdef __cplusplus __inline int operator==(REFGUID guidOne, REFGUID guidOther) { return IsEqualGUID(guidOne,guidOther); } #endif
What is the point of this int ? I understand that C is not of type BOOL , but there is #ifdef __cplusplus , so this code will only be compiled as C ++, so BOOL will be supported anyway. The presence of negation near memcmp() effectively converts all possible values โโreturned from memcmp() to zero and non-zero.
In addition, C does not have only user-defined operators. Only C ++ supports them. Thus, operator== will not compile in C code.
Are there any reasons for choosing int instead of BOOL here?
c ++ visual-c ++ com
sharptooth
source share