Reputation: 15293
Am I safe in casting a C++ bool to a Windows API BOOL via this construct
bool mybool = true;
BOOL apiboolean = mybool ? TRUE : FALSE;
I'd assume this is a yes because I don't see any obvious problems but I wanted to take a moment to ask only because this may be more subtle than it appears.
Thanks to Dima for (gently) pointing out my carelessness in the way I'd originally phrased the question.
Upvotes: 4
Views: 6162
Reputation: 38775
Visual Studio 2005 will simply accept:
bool b = true;
BOOL apiboolean = b;
no casting required.
Note that the other way round BOOL->bool does not simply work like this.
Upvotes: 1
Reputation: 103515
Yes, that will work, but
bool b;
...
BOOL apiboolean = (BOOL) b;
should work just as well, as does the reverse:
bool bb = (bool) apiboolean;
Upvotes: 3
Reputation: 39389
Do you mean
bool b;
...
BOOL apiboolean = b ? TRUE : FALSE;
If so, then yes, this will work.
Upvotes: 10