Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Bool expression

Reply
Thread Tools

Bool expression

 
 
2005
Guest
Posts: n/a
 
      10-27-2006
Hi,

The expression below
bool Full() {return ((mSize==MAXSIZE) ? 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

 
Reply With Quote
 
 
 
 
Jim Langston
Guest
Posts: n/a
 
      10-27-2006
"2005" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Hi,
>
> The expression below
> bool Full() {return ((mSize==MAXSIZE) ? 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.



 
Reply With Quote
 
 
 
 
Mark P
Guest
Posts: n/a
 
      10-27-2006
2005 wrote:
> Hi,
>
> The expression below
> bool Full() {return ((mSize==MAXSIZE) ? 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.
 
Reply With Quote
 
2005
Guest
Posts: n/a
 
      10-27-2006

Jim Langston wrote:
> "2005" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) ups.com...
> > Hi,
> >
> > The expression below
> > bool Full() {return ((mSize==MAXSIZE) ? 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.


 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      10-27-2006
"2005" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
>
> Jim Langston wrote:
>> "2005" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed) ups.com...
>> > Hi,
>> >
>> > The expression below
>> > bool Full() {return ((mSize==MAXSIZE) ? 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).


 
Reply With Quote
 
David Harmon
Guest
Posts: n/a
 
      10-27-2006
On 26 Oct 2006 17:45:22 -0700 in comp.lang.c++, "2005"
<(E-Mail Removed)> wrote,
>The expression below
> bool Full() {return ((mSize==MAXSIZE) ? 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;}


 
Reply With Quote
 
2005
Guest
Posts: n/a
 
      10-27-2006

David Harmon wrote:
> On 26 Oct 2006 17:45:22 -0700 in comp.lang.c++, "2005"
> <(E-Mail Removed)> wrote,
> >The expression below
> > bool Full() {return ((mSize==MAXSIZE) ? 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?

 
Reply With Quote
 
David Harmon
Guest
Posts: n/a
 
      10-27-2006
On 26 Oct 2006 19:33:36 -0700 in comp.lang.c++, "2005"
<(E-Mail Removed)> wrote,
>> 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.

 
Reply With Quote
 
David Harmon
Guest
Posts: n/a
 
      10-27-2006
On Fri, 27 Oct 2006 02:53:15 GMT in comp.lang.c++, David Harmon
<(E-Mail Removed)> wrote,
>On 26 Oct 2006 19:33:36 -0700 in comp.lang.c++, "2005"
><(E-Mail Removed)> wrote,
>>> 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;}

 
Reply With Quote
 
Tim Slattery
Guest
Posts: n/a
 
      10-27-2006
"2005" <(E-Mail Removed)> wrote:

>Hi,
>
>The expression below
> bool Full() {return ((mSize==MAXSIZE) ? 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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Need standard function to do (Bool and Vector) Weng Tianxiang VHDL 2 06-21-2005 12:01 AM
Re: Convert DataRow content to bool Eliyahu Goldin ASP .Net 0 07-07-2003 01:32 PM
Re: Convert DataRow content to bool Ignacio Machin ASP .Net 0 07-07-2003 12:16 PM



Advertisments