- Best C++20 feature - 2 Updates
Manfred <noname@add.invalid>: Jul 27 06:23PM +0200 On 7/26/2019 10:34 PM, Thiago Adams wrote: > HRESULT F() { ... return FALSE; } > The value 0 means OK (S_OK) in HRESULT > This code compiles without error or warning. And S_FALSE is 1 :) But VARIANT_TRUE is -1, and VARIANT_FALSE is 0 :)) Expecting consistency is a lost cause in the MS world, so back to the original point, stuff like strong-typedefs may be useful to enforce consistency, but not in Windows programming. |
David Brown <david.brown@hesbynett.no>: Jul 27 10:41PM +0200 On 26/07/2019 22:21, Bart wrote: >> I think strong-typedefs are useful. In windows HRESULT and BOOL can >> be mixed causing errors, for instance. > HRESULT is defined as 'long', an int, so not that much can go wrong. Lots and lots can go wrong with a type like that being just a typedef for an int or a long int. > It's also intended to hold a result, which can be 'bool'. > But it's also misnamed as it is not a handle, which generally are > pointers; those can't be mixed up with bools. Handles are sometimes implemented with pointers, sometimes with integer indexes or other ways of storing data. The point of a handle type is it should be different from pointers or anything else - it should be more abstract, and with limited features. You should not be able to dereference it like a pointer - you should be able to receive it from an allocation function, pass it around to other API functions, and hand it in to a deallocation function. Sensible handle types in C are always strong types - a struct (or even a union) in C, a struct, class or strong enum in C++. |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment