bool to int cast

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MathWizard

    bool to int cast

    Hi all,

    I was wondering how the cast from bool to an integer is defined. I guess
    that 'false' always leads to '0', but I'm not sure that 'true' always
    leads to '1'. Is it possible that 'true' casts tot something like
    'non-zero' and thus can take any positive value?

    Jeroen
  • Robert Bauck Hamar

    #2
    Re: bool to int cast

    MathWizard wrote:
    Hi all,
    >
    I was wondering how the cast from bool to an integer is defined. I guess
    that 'false' always leads to '0', but I'm not sure that 'true' always
    leads to '1'. Is it possible that 'true' casts tot something like
    'non-zero' and thus can take any positive value?
    No, int(true) is always 1. And int(false) is always 0.

    --
    rbh

    Comment

    • Jim Langston

      #3
      Re: bool to int cast

      "MathWizard " <no_mail@please .comwrote in message
      news:46928112$0 $19821$e4fe514c @dreader16.news .xs4all.nl...
      Hi all,
      >
      I was wondering how the cast from bool to an integer is defined. I guess
      that 'false' always leads to '0', but I'm not sure that 'true' always
      leads to '1'. Is it possible that 'true' casts tot something like
      'non-zero' and thus can take any positive value?
      From bool to int, false is always 0, true is always 1.
      From int to bool, 0 is always false, anything other than 0 is true.


      Comment

      • Jojo

        #4
        Re: bool to int cast

        Jim Langston schreef:
        "MathWizard " <no_mail@please .comwrote in message
        news:46928112$0 $19821$e4fe514c @dreader16.news .xs4all.nl...
        >Hi all,
        >>
        >I was wondering how the cast from bool to an integer is defined. I guess
        >that 'false' always leads to '0', but I'm not sure that 'true' always
        >leads to '1'. Is it possible that 'true' casts tot something like
        >'non-zero' and thus can take any positive value?
        >
        From bool to int, false is always 0, true is always 1.
        From int to bool, 0 is always false, anything other than 0 is true.
        >
        >
        OK, thanks guys.

        Comment

        Working...