Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logical !! versus nothing

Tags:

c++

c

com

I just found this in Microsoft's guiddef.h header file:

__inline bool operator==(REFGUID guidOne, REFGUID guidOther)
{
    return !!IsEqualGUID(guidOne,guidOther);
}

Is there any point to the !!, or was some dev just feeling cute that day?

like image 310
fieldtensor Avatar asked Aug 13 '14 21:08

fieldtensor


2 Answers

It turns off Visual C++ silly performance warning for the conversion to boolean.

like image 67
Cheers and hth. - Alf Avatar answered Nov 15 '22 07:11

Cheers and hth. - Alf


In this particular case, Alf is probably right.

Otherwise it is common idiom to standardize integer values to either 1 (if they start nonzero) or 0 (if they start as zero) for logical operations.

like image 5
Xarn Avatar answered Nov 15 '22 07:11

Xarn