RFC: small syscons and kbd patch

Garrett Cooper yanefbsd at gmail.com
Fri Dec 5 01:31:13 PST 2008


On Fri, Dec 5, 2008 at 1:11 AM, Christoph Mallon
<christoph.mallon at gmx.de> wrote:
> Garrett Cooper schrieb:
>>
>> (I feel like I'm getting off on a bikeshed topic, but...)
>>
>> 1. What dialect of C was it defined in? Is it still used in the
>> standard dialect (honestly, this is the first time I've ever seen it
>> before, but then again I am a younger generation user)?
>
> Dialect? The ! operator is plain vanilla standard C. It takes a scalar
> operand and returns 1, if it compares equal to 0, otherwise it returns 0.
> !!, i.e. two consecutive ! operators, is one of the oldest tricks in the
> book, right next to (a > b) - (a < b) for comparison functions and countless
> other idioms.
>
>> 3. What's the real loss of going to `? :', beyond maybe 3 extra
>> keystrokes if it's easier for folks who may not be as experienced to
>> read?
>
> I'd like my bikeshed grass green, please.
>
>        Christoph

If you really want to split hairs, ! only negates the logic value,
whereas ~ actually negates the bits. So technically, you're not
flipping 0 to make 1 and vice versa, but instead flipping 0 to make
non-zero, etc. There is a clear distinction in hardware.

The point was that !! isn't obvious at first glancing the C code. It's
important for code to be readable as well as functional (that's why we
have style(9)). Getting down to it I'd like to see what the compiler
optimizes each as, because I can see dumb compilers saying `!!'
translates to `not, bne => set, else set, continue', whereas `? :'
could be translated to `bne, set, else set, continue'; I'm sure gcc
has moved passed these really minute details.

Hopefully this helps shed more light on where I'm coming from.

-Garrett


More information about the freebsd-hackers mailing list