Re: [re-post] why no output



James Kuyper <jameskuyper@xxxxxxxxxxx> writes:
Franken Sense wrote:
In Dread Ink, the Grave Hand of Mark McIntyre Did Inscribe:

On 14/05/09 05:58, Franken Sense wrote:
This compiles. Why no output?
....
int main(void)
{
....
while((len = get_script(fp, text, NUMBER))> 0)
why are you comparing a bool to zero?

Surely you want to loop while get_script is returning
data. Currently it loops as long as false > 0. Is it?

I thought it would work since 1 > 0.

But if you're bothering to declare it as returning bool rather than
int, and if all of your return statements use either true or false,
you should be comparing its return value with true or false, rather
than numeric values. This is purely a style issue; but then so is the
use of bool in the first place.

No, you should never declare a boolean value to true or false. Just
test the value.

Rather than "if (cond == true)", just write "if (cond)".
Rather than "if (cond == false)", just write "if (!cond)".

(But "len" is an odd name for a boolean anyway.)

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • Re: Create a file larger than 3 gb
    ... DWORD dwBytesWrite, dwSize; ... EVER compare a boolean to a literal truth value! ... and do it OUTSIDE the loop, since there is no reason to zero it a second, ... but what are you comparing it to? ...
    (microsoft.public.vc.mfc)
  • Re: Create a file larger than 3 gb
    ... DWORD dwBytesWrite, dwSize; ... EVER compare a boolean to a literal truth value! ... since there is no reason to introduce a gratuitous boolean variable to the loop. ... but what are you comparing it to? ...
    (microsoft.public.vc.mfc)
  • Re: Create a file larger than 3 gb
    ... EVER compare a boolean to a literal truth value! ... since there is no reason to introduce a gratuitous boolean variable to the loop. ... If you are using the Hungarian Notation correctly, dwSize is a DWORD. ... but what are you comparing it to? ...
    (microsoft.public.vc.mfc)
  • Re: OnPaint & BMP question
    ... No, what I mean is if you have a bool or BOOL, you just USE it! ... A boolean value is either true or false. ... COMPARING to true or false is silly ... is as silly as writing ...
    (microsoft.public.vc.mfc)
  • Re: [re-post] why no output
    ... why are you comparing a bool to zero? ... Surely you want to loop while get_script is returning data. ... But if you're bothering to declare it as returning bool rather than int, and if all of your return statements use either true or false, you should be comparing its return value with true or false, rather than numeric values. ...
    (comp.lang.c)