Why use !! when converting int to bool?

The problems with the “!!” idiom are that it’s terse, hard to see, easy to mistake for a typo, easy to drop one of the “!’s”, and so forth. I put it in the “look how cute we can be with C/C++” category. Just write bool isNonZero = (integerValue != 0); … be clear.

Convert integer to hex and hex to integer

Convert INT to hex: SELECT CONVERT(VARBINARY(8), 16777215) Convert hex to INT: SELECT CONVERT(INT, 0xFFFFFF) Update 2015-03-16 The above example has the limitation that it only works when the HEX value is given as an integer literal. For completeness, if the value to convert is a hexadecimal string (such as found in a varchar column) use: … Read more

Why can’t I inherit from int in C++?

Neil’s comment is pretty accurate. Bjarne mentioned considering and rejecting this exact possibility1: The initializer syntax used to be illegal for built-in types. To allow it, I introduced the notion that built-in types have constructors and destructors. For example: int a(1); // pre-2.1 error, now initializes a to 1 I considered extending this notion to … Read more