[Toybox] PM: code style, was: Re: New Subscriber
Rob Landley
rob at landley.net
Wed Feb 15 04:10:38 PST 2012
On 02/12/2012 06:07 PM, Frank Bergmann wrote:
> Hi,
>
> On Sat, Feb 11, 2012 at 02:28:15PM -0600, Rob Landley wrote:
> [...]
>> execution units busy are much happier with:
>> x = 42;
>> if (blah) x = 37;
>> Than with:
>> x = blah ? 42 : 37.
>
> ... at least it is better readable if you use this nice kernel macros
> __likely() and unlikely(). ;-)
The kernel is always running when any program does, so
micro-optimizations they do affect every single load you ever run. The
kernel guys have a huge incentive to microoptimize... and then undo it
again when their microoptimizations bitrot:
http://lwn.net/Articles/419102/
http://lwn.net/Articles/404103/
http://lwn.net/Articles/444336/
http://lwn.net/Articles/166172/
I like to be aware of this sort of thing so I don't gratuitously screw
it up, but I don't want to try to micromanage the compiler because
different builds (for different chips with different compiler versions)
need different things.
>>> Are you sure? For K&R I'm sure that it is but IMHO c99 "requires" the
>>> usage of void in this case (using char** as char*).
>>
>> Can you point me to where in the spec?
>
> Did I wrote "IMHO"? ;-) K&R IMHO doesn't know anything about void. A
> pointer char* was the universal pointer which may be "converted" (without
> explicit casting) to any other pointer and vice versa. C99 (and the
> standard before it) IMHO introduced void at least for this role. And IMHO
> a non-explicit cast is only allowed for void* and not for char* anymore.
This is the _compiler_ goign overboard with microoptimizations, if you
ask me. I treat it the same way I treat the "may be used uninitialized,
even though it isn't in this case" warning. (Which you can apparently
disable with "int x=x;" in your declarations, which is a syntax
specifically to tell it to shut up about that, but still way too magic
for my tastes.)
Rob
1329307838.0
More information about the Toybox
mailing list