Bool expression

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

    #1

    Bool expression

    Hi,

    The expression below
    bool Full() {return ((mSize==MAXSIZ E) ? true : false);}

    My question is if (mSize==MAXSIZE ), would it return 1 or 0?

    Of course I ran the code but it conflicts with the spec that I wanted
    to get a second opinion.

    Thanks

  • Jim Langston

    #2
    Re: Bool expression

    "2005" <uws2003@yahoo. comwrote in message
    news:1161909922 .727130.54480@h 48g2000cwc.goog legroups.com...
    Hi,
    >
    The expression below
    bool Full() {return ((mSize==MAXSIZ E) ? true : false);}
    >
    My question is if (mSize==MAXSIZE ), would it return 1 or 0?
    >
    Of course I ran the code but it conflicts with the spec that I wanted
    to get a second opinion.
    >
    Thanks
    I don't understand your question. If mSize is equal to MAXSIZE the function
    will return true, otherwise it woudl return false, but I don't know why it
    just wasn't coded

    return mSize == MAXSIZE;
    which would do the exact same thing.



    Comment

    • Mark P

      #3
      Re: Bool expression

      2005 wrote:
      Hi,
      >
      The expression below
      bool Full() {return ((mSize==MAXSIZ E) ? true : false);}
      >
      My question is if (mSize==MAXSIZE ), would it return 1 or 0?
      Neither, it returns "true". Of course, it would be simpler to write:

      return mSize == MAXSIZE;

      If for some reason the result were converted to an integral type, than
      it would be 1, not 0.

      Comment

      • 2005

        #4
        Re: Bool expression


        Jim Langston wrote:
        "2005" <uws2003@yahoo. comwrote in message
        news:1161909922 .727130.54480@h 48g2000cwc.goog legroups.com...
        Hi,

        The expression below
        bool Full() {return ((mSize==MAXSIZ E) ? true : false);}

        My question is if (mSize==MAXSIZE ), would it return 1 or 0?

        Of course I ran the code but it conflicts with the spec that I wanted
        to get a second opinion.

        Thanks
        >
        I don't understand your question. If mSize is equal to MAXSIZE the function
        will return true, otherwise it woudl return false, but I don't know why it
        just wasn't coded
        >
        Well, the function above and a spec was given.
        My question is when it returns true, would it be 1 or 0? eg if (Full(
        <true)) == 1 or 0 ?
        return mSize == MAXSIZE;
        which would do the exact same thing.

        Comment

        • Jim Langston

          #5
          Re: Bool expression

          "2005" <uws2003@yahoo. comwrote in message
          news:1161913460 .960087.219290@ e3g2000cwe.goog legroups.com...
          >
          Jim Langston wrote:
          >"2005" <uws2003@yahoo. comwrote in message
          >news:116190992 2.727130.54480@ h48g2000cwc.goo glegroups.com.. .
          Hi,
          >
          The expression below
          bool Full() {return ((mSize==MAXSIZ E) ? true : false);}
          >
          My question is if (mSize==MAXSIZE ), would it return 1 or 0?
          >
          Of course I ran the code but it conflicts with the spec that I wanted
          to get a second opinion.
          >
          Thanks
          >>
          >I don't understand your question. If mSize is equal to MAXSIZE the
          >function
          >will return true, otherwise it woudl return false, but I don't know why
          >it
          >just wasn't coded
          >>
          >
          Well, the function above and a spec was given.
          My question is when it returns true, would it be 1 or 0? eg if (Full(
          <true)) == 1 or 0 ?
          >
          >return mSize == MAXSIZE;
          >which would do the exact same thing.
          It doesn't return either, it returns true, a boolean value. If you cast a
          boolean value to an int, true will become 1 and false will become 0, but
          there is no guarantee that the boolean value itself is stored that way. The
          compiler is free to store it anyway it wants I understand (one bit, a byte,
          a word, whatever).


          Comment

          • David Harmon

            #6
            Re: Bool expression

            On 26 Oct 2006 17:45:22 -0700 in comp.lang.c++, "2005"
            <uws2003@yahoo. comwrote,
            >The expression below
            > bool Full() {return ((mSize==MAXSIZ E) ? true : false);}
            >
            >My question is if (mSize==MAXSIZE ), would it return 1 or 0?
            No, it would return true or false.
            By the way, for directness and clarity that should be written as:

            bool Full() {return mSize==MAXSIZE; }


            Comment

            • 2005

              #7
              Re: Bool expression


              David Harmon wrote:
              On 26 Oct 2006 17:45:22 -0700 in comp.lang.c++, "2005"
              <uws2003@yahoo. comwrote,
              The expression below
              bool Full() {return ((mSize==MAXSIZ E) ? true : false);}

              My question is if (mSize==MAXSIZE ), would it return 1 or 0?
              >
              No, it would return true or false.
              By the way, for directness and clarity that should be written as:
              >
              bool Full() {return mSize==MAXSIZE; }
              My requirement was to return a 0 when mSize==MAXSIZE.

              I coded and did
              int tmp = Ful(); and found tmp was 1 when mSize==MAXSIZE

              Is it contradictory to what you are saying?

              Comment

              • David Harmon

                #8
                Re: Bool expression

                On 26 Oct 2006 19:33:36 -0700 in comp.lang.c++, "2005"
                <uws2003@yahoo. comwrote,
                > bool Full() {return mSize==MAXSIZE; }
                >
                >My requirement was to return a 0 when mSize==MAXSIZE.
                Well, that is actually the opposite of your original example.
                In that case, make it

                int Full() {return mSize!=MAXSIZE; }

                ^^^ Note change of return type. If you want to return 0 or 1,
                don't call it bool.

                Either way, adding ?: is just obfuscation.

                Comment

                • David Harmon

                  #9
                  Re: Bool expression

                  On Fri, 27 Oct 2006 02:53:15 GMT in comp.lang.c++, David Harmon
                  <source@netcom. comwrote,
                  >On 26 Oct 2006 19:33:36 -0700 in comp.lang.c++, "2005"
                  ><uws2003@yahoo .comwrote,
                  >> bool Full() {return mSize==MAXSIZE; }
                  >>
                  >>My requirement was to return a 0 when mSize==MAXSIZE.
                  Oh, and if you are going to return 0 when the crock is full and 1
                  when it is not. then it should be

                  int not_full() {return mSize!=MAXSIZE; }

                  Comment

                  • Tim Slattery

                    #10
                    Re: Bool expression

                    "2005" <uws2003@yahoo. comwrote:
                    >Hi,
                    >
                    >The expression below
                    > bool Full() {return ((mSize==MAXSIZ E) ? true : false);}
                    >
                    >My question is if (mSize==MAXSIZE ), would it return 1 or 0?
                    Neither one. It would return true, which is a boolean value, not an
                    integer.

                    --
                    Tim Slattery
                    Slattery_T@bls. gov

                    Comment

                    • Clark S. Cox III

                      #11
                      Re: Bool expression

                      Jim Langston wrote:
                      "2005" <uws2003@yahoo. comwrote in message
                      news:1161913460 .960087.219290@ e3g2000cwe.goog legroups.com...
                      >Jim Langston wrote:
                      >>"2005" <uws2003@yahoo. comwrote in message
                      >>news:11619099 22.727130.54480 @h48g2000cwc.go oglegroups.com. ..
                      >>>Hi,
                      >>>>
                      >>>The expression below
                      >>>bool Full() {return ((mSize==MAXSIZ E) ? true : false);}
                      >>>>
                      >>>My question is if (mSize==MAXSIZE ), would it return 1 or 0?
                      >>>>
                      >>>Of course I ran the code but it conflicts with the spec that I wanted
                      >>>to get a second opinion.
                      >>>>
                      >>>Thanks
                      >>I don't understand your question. If mSize is equal to MAXSIZE the
                      >>function
                      >>will return true, otherwise it woudl return false, but I don't know why
                      >>it
                      >>just wasn't coded
                      >>>
                      >Well, the function above and a spec was given.
                      >My question is when it returns true, would it be 1 or 0? eg if (Full(
                      ><true)) == 1 or 0 ?
                      >>
                      >>return mSize == MAXSIZE;
                      >>which would do the exact same thing.
                      >
                      It doesn't return either, it returns true, a boolean value. If you cast a
                      boolean value to an int, true will become 1 and false will become 0, but
                      there is no guarantee that the boolean value itself is stored that way.
                      s/cast/convert/
                      The difference is significant; (There are no casts in the following
                      snippet):

                      int i = true;
                      int j = false;
                      bool k = 0;
                      bool l = 42;
                      The compiler is free to store it anyway it wants I understand (one bit, a byte,
                      a word, whatever).

                      --
                      Clark S. Cox III
                      clarkcox3@gmail .com

                      Comment

                      Working...