Skip to contentSkip to conversation

2.4.21-rc1 pointless IDE noise reduction

PATCH Chuck Ebbert 5 participants 9 messages Apr 24, 2003 – Apr 25, 2003

lore
Share & tools
lore
#0 lore raw
Quoted 4 lines · Jens Axboe

Review

Quoted 2 lines
(quoted diff) +1 -0
+	return((drive->id->cfs_enable_1 & 0x0400) ? 1 : 0);
 }

Seconded, it causes a lot more confusion than it does good.

The return looks like a function call in that last line.

That's one of the few things I find really annoying -- extra parens
are fine when they make code clearer, but not there.

-------
Chuck [ C Style Police, badge #666 ]

#1 lore raw
Quoted 8 lines · Chuck Ebbert
Quoted 4 lines · Jens Axboe

Review

Quoted 2 lines
(quoted diff) +1 -0
+	return((drive->id->cfs_enable_1 & 0x0400) ? 1 : 0);
 }

Seconded, it causes a lot more confusion than it does good.

Quoted 8 lines

The return looks like a function call in that last line.

That's one of the few things I find really annoying -- extra parens
are fine when they make code clearer, but not there.

-------
Chuck [ C Style Police, badge #666 ]

return((drive->id->cfs_enable_1 & 0x0400) ? 1 : 0);
                                  ^^^^^^|__________ wtf?

These undefined numbers in the code are much more annoying to me... but I don't have a C Style Police Badge.

Also, whatever that is, 0x400, I'll call it MASK, can have shorter code like:

return (drive->id->cfs_enable_1 && MASK); // TRUE/FALSE
... for pedantics...
return (int) (drive->id->cfs_enable_1 && MASK);

Okay, gimmie a C Police Badge.......

Cheers,
Dick Johnson
Penguin : Linux version 2.4.20 on an i686 machine (797.90 BogoMips). Why is the government concerned about the lunatic fringe? Think about it.

#2 lore raw
Quoted 32 lines · Richard B. Johnson
Quoted 12 lines · Chuck Ebbert
Quoted 7 lines · Jens Axboe
Quoted 4 lines
(quoted diff) +1 -0
+	return((drive->id->cfs_enable_1 & 0x0400) ? 1 : 0);

}

Seconded, it causes a lot more confusion than it does good.

Quoted 10 lines

The return looks like a function call in that last line.

That's one of the few things I find really annoying -- extra parens
are fine when they make code clearer, but not there.

-------
Chuck [ C Style Police, badge #666 ]

return((drive->id->cfs_enable_1 & 0x0400) ? 1 : 0);
                                 ^^^^^^|__________ wtf?

These undefined numbers in the code are much more annoying to me... but I don't have a C Style Police Badge.

Quoted 10 lines

Also, whatever that is, 0x400, I'll call it MASK, can have shorter code like:

return (drive->id->cfs_enable_1 && MASK); // TRUE/FALSE
... for pedantics...
return (int) (drive->id->cfs_enable_1 && MASK);

That wouldn't work, because && isn't a bitwise operator. But I agree that the ( x ? 1 : 0 ) method may not be very efficient, because it may involve branches.

Two alternatives:

(a) !!(x & 0x400)

(b) (x & 0x400) >> 10

#3 lore raw
Quoted 51 lines · Timothy Miller
Quoted 32 lines · Richard B. Johnson
Quoted 12 lines · Chuck Ebbert
Quoted 7 lines · Jens Axboe
Quoted 4 lines
(quoted diff) +1 -0
+	return((drive->id->cfs_enable_1 & 0x0400) ? 1 : 0);

}

Seconded, it causes a lot more confusion than it does good.

Quoted 10 lines

The return looks like a function call in that last line.

That's one of the few things I find really annoying -- extra parens
are fine when they make code clearer, but not there.

-------
Chuck [ C Style Police, badge #666 ]

return((drive->id->cfs_enable_1 & 0x0400) ? 1 : 0);
                                 ^^^^^^|__________ wtf?

These undefined numbers in the code are much more annoying to me... but I don't have a C Style Police Badge.

Quoted 10 lines

Also, whatever that is, 0x400, I'll call it MASK, can have shorter code like:

return (drive->id->cfs_enable_1 && MASK); // TRUE/FALSE
... for pedantics...
return (int) (drive->id->cfs_enable_1 && MASK);

That wouldn't work, because && isn't a bitwise operator. But I agree that the ( x ? 1 : 0 ) method may not be very efficient, because it may involve branches.

Quoted 6 lines

Two alternatives:

(a) !!(x & 0x400)

(b) (x & 0x400) >> 10

I meant return ((foo & MASK) && 1);

Try it, you'll like it! No shifts, no jumps.

int main()

{
    int foo = 0x12340400;
    printf("%d\n", ((foo & 0x400) && 1));
    printf("%d\n", ((foo & 0x300) && 1));
    printf("%d\n", ((foo & 0x500) && 1));
}

Cheers,
Dick Johnson
Penguin : Linux version 2.4.20 on an i686 machine (797.90 BogoMips). Why is the government concerned about the lunatic fringe? Think about it.

#4 lore raw
Quoted 8 lines

I meant return ((foo & MASK) && 1);

Try it, you'll like it! No shifts, no jumps.

Looks sweet! If the compiler is smart, that is. I'll add that to my repetoire. I'll have to see what the asm output looks like.

#5 lore raw

Hi !

Well, although I usually don't like these endless coding-style threads, why don't you simply use this common form ? :

    return !!(foo & MASK);

I found that the compilers like it much and easily emit conditionnal set instructions. Eg, on x86, this should be something like :

testl MASK, foo
setnz retcode

Cheers,
Willy

Quoted 11 lines · Timothy Miller
Quoted 8 lines

I meant return ((foo & MASK) && 1);

Try it, you'll like it! No shifts, no jumps.

Looks sweet! If the compiler is smart, that is. I'll add that to my repetoire. I'll have to see what the asm output looks like.

#6 lore raw
Quoted 5 lines · Willy Tarreau

Hi !

Well, although I usually don't like these endless coding-style threads, why don't you simply use this common form ? :

Quoted 12 lines
   return !!(foo & MASK);

I found that the compilers like it much and easily emit conditionnal set instructions. Eg, on x86, this should be something like :

testl MASK, foo
setnz retcode

That was the first thing I'd suggested.

Let's canonize (in the "add to the canon" sense) this. :)

#7 lore raw
In reply to Richard B. Johnson
Quoted 10 lines · Richard B. Johnson
Quoted 6 lines

Two alternatives:

(a) !!(x & 0x400)

(b) (x & 0x400) >> 10

I meant return ((foo & MASK) && 1);

Try it, you'll like it! No shifts, no jumps.

Sorry, I still find !!(foo & MASK) easier to read, because !! is only used to convert to boolean. Sort of a "boolean cast" in effect. It jumps out at you what is intended.

Anyway, a matter of taste, both generate jumpless code.

Signature · 3 lines
bill davidsen <[email protected]>
  CTO, TMR Associates, Inc
Doing interesting things with little computers since 1979.
#8 lore raw
Quoted 12 lines · Bill Davidsen
Quoted 9 lines · Richard B. Johnson
Quoted 6 lines

Two alternatives:

(a) !!(x & 0x400)

(b) (x & 0x400) >> 10

I meant return ((foo & MASK) && 1);

Quoted 7 lines
Quoted 1 line

Try it, you'll like it! No shifts, no jumps.

Sorry, I still find !!(foo & MASK) easier to read, because !! is only used to convert to boolean. Sort of a "boolean cast" in effect. It jumps out at you what is intended.

Anyway, a matter of taste, both generate jumpless code.

Yes, you win. This looks good, both as code and as op-codes on Intel...
#include <stdio.h>
int main()

{
    int i;
    int mask = 0x40;
    for(i=0; i< 0x1000; i++)
        printf("%08x\n", !!(i & mask));
}

You need to actually change something, hense the for() loop. Otherwise gcc just optimizes everything to a 1!

Cheers,
Dick Johnson
Penguin : Linux version 2.4.20 on an i686 machine (797.90 BogoMips). Why is the government concerned about the lunatic fringe? Think about it.