Skip to content
DevMeme
7121 of 7590
Microsoft Post #7807 · source on Telegram

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

14
Anonymous ★ Top Pick Win32's BOOL has three values because backwards compatibility means never having to say your type system is sorry
  1. Anonymous ★ Top Pick

    Win32's BOOL has three values because backwards compatibility means never having to say your type system is sorry

  2. Anonymous

    It's a `BOOL`; the third truth value is 'check GetLastError, coward.'

  3. @TheFloofyFloof 5mo

    technically valid

  4. @gremion_cto 5mo

    Winapi vibes

    1. @SamsonovAnton 5mo

      WomenAPI vibes, where "yes" may as well have a negative meaning, and "no" may be an acknowledgement ("no problem"). 💅

  5. @gremion_cto 5mo

    Yeah! I was right! https://github.com/microsoft/CsWin32/issues/362

  6. @deadgnom32 5mo

    but -1 IS nonzero

    1. @blue_bonsai 5mo

      Shhhhh don't break it down to them.

  7. Егор 5mo

    zoomers discovered winapi BOOL is not boolean typedef int BOOL;

  8. @sysoevyarik 5mo

    >tristate Phineas and ferb ahh programming

  9. @blue_bonsai 5mo

    What

  10. @b7sum 5mo

    whar.

  11. @azizhakberdiev 5mo

    I find it stupid how we have a 1 bit type when all machines are 8 bit addressible

    1. @purplesyringa 5mo

      bool is useful as an abstraction, not as a fixed-width type

Use J and K for navigation