473,396 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Bool expression

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

Oct 27 '06 #1
10 2236
"2005" <uw*****@yahoo.comwrote in message
news:11*********************@h48g2000cwc.googlegro 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.

Oct 27 '06 #2
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.
Oct 27 '06 #3

Jim Langston wrote:
"2005" <uw*****@yahoo.comwrote in message
news:11*********************@h48g2000cwc.googlegro 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.
Oct 27 '06 #4
"2005" <uw*****@yahoo.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
>
Jim Langston wrote:
>"2005" <uw*****@yahoo.comwrote in message
news:11*********************@h48g2000cwc.googlegr oups.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).
Oct 27 '06 #5
On 26 Oct 2006 17:45:22 -0700 in comp.lang.c++, "2005"
<uw*****@yahoo.comwrote,
>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;}
Oct 27 '06 #6

David Harmon wrote:
On 26 Oct 2006 17:45:22 -0700 in comp.lang.c++, "2005"
<uw*****@yahoo.comwrote,
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?

Oct 27 '06 #7
On 26 Oct 2006 19:33:36 -0700 in comp.lang.c++, "2005"
<uw*****@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.

Oct 27 '06 #8
On Fri, 27 Oct 2006 02:53:15 GMT in comp.lang.c++, David Harmon
<so****@netcom.comwrote,
>On 26 Oct 2006 19:33:36 -0700 in comp.lang.c++, "2005"
<uw*****@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;}

Oct 27 '06 #9
"2005" <uw*****@yahoo.comwrote:
>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
Sl********@bls.gov
Oct 27 '06 #10
Jim Langston wrote:
"2005" <uw*****@yahoo.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
>Jim Langston wrote:
>>"2005" <uw*****@yahoo.comwrote in message
news:11*********************@h48g2000cwc.googleg roups.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.
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
cl*******@gmail.com
Oct 27 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: klaas | last post by:
the following code gives rise to the beneath error message, only when a matrix object is instantiated as matrix<bool>, not with matrix<float>: /*returns a reference to the object at position...
64
by: shaanxxx | last post by:
I have code which says #define MYBOOL int This code is very old. people who have written is not avaible. I was thinking what could be reason. 1) bool datatype was not available that time (10...
23
by: Saizan | last post by:
Why subclassing bool from int either __invert__ or __neg__ haven't been overrided to produce a boolean negation? I suspect backwards compatibility or something alike, but I still wonder.. And...
2
by: Jakub Bednarczuk | last post by:
Hi everybody I am trying to find the solution for the problem stated in the topic, but so far without any result. Let's see the problem. I have set of conditions and the description (logical...
13
by: rcoco | last post by:
Hi, How could i translate Bool(VB) into c#? Thanks
4
by: lumpybanana247 | last post by:
I have this script.... #include "Library.h" bool Battle () { int YourHealth; int TheRatsHealth;
15
by: ssylee | last post by:
I am using mikroC to program some microcontroller code in C. However I have come across of potential problem of bool type not being supported from the compiler complaint on how I declared type bool...
32
by: Simon L | last post by:
BOOL bMyarray; memset(bMyArray , 0xFF, sizeof(BOOL) * 1000); clean & quick until someone else's code found I was returning -1 to mean true Because my BOOL is 4 bytes long, TRUE in memory...
2
by: Marcel Kloubert | last post by:
Hi! Example: public bool? IsChecked { get { throw new NotImplementedException(); } } What does the question mark after the bool mean ("bool?")?
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.