Win32 GetMessage: The BOOL That Returns Nonzero, Zero, or -1
Description
A dark-themed screenshot of Microsoft's Win32 API documentation for the GetMessage function's 'Return value' section. It states the type is 'BOOL' (highlighted), then explains: if the function retrieves a message other than WM_QUIT, the return value is nonzero; if it retrieves the WM_QUIT message, the return value is zero; if there is an error, the return value is -1 - for example if hWnd is an invalid window handle or lpMsg is an invalid pointer, with GetLastError for extended info. The final line, with 'the return value can be nonzero, zero, or -1' highlighted, reads 'Because the return value can be nonzero, zero, or -1, avoid code like this:'. The humor is the self-evident absurdity of a 'boolean' type with three meaningful states, a legendary Win32 API design wart that has caused countless message-loop bugs from 'while (GetMessage(...))' patterns
Comments
14Comment deleted
Win32's BOOL has three values because backwards compatibility means never having to say your type system is sorry
It's a `BOOL`; the third truth value is 'check GetLastError, coward.'
technically valid Comment deleted
Winapi vibes Comment deleted
WomenAPI vibes, where "yes" may as well have a negative meaning, and "no" may be an acknowledgement ("no problem"). 💅 Comment deleted
Yeah! I was right! https://github.com/microsoft/CsWin32/issues/362 Comment deleted
but -1 IS nonzero Comment deleted
Shhhhh don't break it down to them. Comment deleted
zoomers discovered winapi BOOL is not boolean typedef int BOOL; Comment deleted
>tristate Phineas and ferb ahh programming Comment deleted
What Comment deleted
whar. Comment deleted
I find it stupid how we have a 1 bit type when all machines are 8 bit addressible Comment deleted
bool is useful as an abstraction, not as a fixed-width type Comment deleted