Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Broadcom Open-Sources Wireless Drivers

Name: Anonymous 2010-09-09 15:26

The ternary operator is dissapointed.


/*
Description: This function saturate input 32 bit number into a 16 bit number.
If input number is greater than 0x7fff then output is saturated to 0x7fff.
else if input number is less than 0xffff8000 then output is saturated to 0xffff8000
else output is same as input.
*/
int16 qm_sat32(int32 op)
{
    int16 result;
    if (op > (int32) 0x7fff) {
        result = 0x7fff;
    } else if (op < (int32) 0xffff8000) {
        result = (int16) (0x8000);
    } else {
        result = (int16) op;
    }
    return result;
}

Name: Anonymous 2010-09-13 19:40

>>42
Agreed. As a general rule I use uppercase only for badly behaved macros (either they evaluate their arguments multiple times, or they open a block and cannot be used in an expression, or something else funny.) If a macro behaves like a function, then you won't need to know it's not a function, so there is no reason it can't be named like a function.

If >>40 enclosed the block in parens (making it a statement expr) and used typeof it would actually work in GCC, Clang, and a few others. I'd rather have portability though.

In any case clamp() is a completely retarded and brain-dead example because there is no reason it shouldn't just be a function.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List