Page 1 of 1

Lazarus – cint or integer to boolean

Lazarus – cint or integer to boolean

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
Examples: "MacOS X - Your question", "MS Word - Your Tip or Trick".

Please note that switching to another language when reading a post will not work!
Posts will not have a translated counterpart.




RSS Feed

Home Forums Software Development Delphi, Lazarus, Free Pascal Lazarus – cint or integer to boolean

This topic contains 0 replies, has 1 voice, and was last updated by  hans 3 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • 11847

    hans
    Keymaster

    Sometimes, especially when using C-libraries, a function may return an integer or a cint (C-integer) where one would expect a boolean.

    To convert this integer value to a boolean, a few facts first;

    The value for “False” is typically stored as 0 (zero),
    and the value for “True” is typically anything else (non-zero).

    Note:
    Most of the time “True” returns as “-1” which is because the Boolean data type is stored as a 16-bit signed integer.
    In this construct −1 (true) evaluates to 16 binary 1’s (11111111 11111111),
    and 0 (false) as 16 binary 0’s (00000000 00000000 – the Boolean value False). 

Viewing 1 post (of 1 total)



You must be logged in to reply to this topic.