Re: Paying developers to get features faster

From: Casper H.S. Dik (Casper.Dik_at_Sun.COM)
Date: 01/25/04


Date: 25 Jan 2004 09:21:49 GMT

newstmp@sinodun.org.uk (John Winters) writes:

>Having said that, I'm out of the mainstream and do consider "if (ptr)"
>to be bad programming style. It's perfectly legal C (and guaranteed
>to work) but I prefer to make the code as self-documenting as possible.
>I would thus recommend:

> if (ptr != NULL)
> if (counter != 0)
> if (flag)

"Pointers are not Booleans" is one of rules in Sun C-style guide.

>The trick of "if (ptr)" arose in the days before compilers had optimizers,
>and could actually result in more efficient code than the fuller version.
>Despite this advantage having long since been eliminated, it still
>hangs around.

I'm not sure if it's optimier related; in both cases the compiler need
to generate a "cmp <var>,0; bne"; (hm, unless perhaps you have a
instruction set which has a special instruction for comparison to 0)

Casper

-- 
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.

Quantcast