On Tue, 16 May 2006 18:55:16 +1200
Rex Johnston <[EMAIL PROTECTED]> wrote:

> Dale DuRose wrote:
> > #include <stdio.h>
> > int main(){
> >        int i;
> >        for(i = 4; i; i--){
> >                printf("%d\n", i);
> >        }
> > }
> > 
> > output is:
> > 4
> > 3
> > 2
> > 1
> > 
> > So thats four loops the statement is false when i is 0.
> 
> C doesn't have a boolean type.  Have a look in a header file and you'll see
> #define TRUE 1
> #define FALSE 0
> 
> In reality, 0 is false, non-zero is true.
> 
> You'll see this all over the place, like
> 
> if( !strchr( haystack, needle ) )
> ...
> 
> Cheers, Rex

That's not strictly true. Or at least didn't used to be

#define TRUE ~FALSE 

is the usual one.

Even though you see this coding a lot, it's still lazy. Especially when a lot 
of code returns 0 on success, and an error code on failure! Makes for difficult 
reading

for loops are defined as 

  for ( initial configuration,...; End conditon; iteration action,... )
  {
        do something...
  }

The other appalling shortcut at this point is missing out the braces and just 
using the next line as the 'do something' bit. Great until you need to do more 
than one thing, and forget.

Those who indent as follows...

  for ( initial configuration,...; End conditon; iteration action,... ) {
        do something...
  }

are adopting a method designed to save paper on a hardcopy teletype, so beware!

My $0.02,


Steve
C bodger since 1984. K&R rules!

Reply via email to