Re: page_launder() bug

Helge Hafting
2001-05-08T07:52:58Z

"J . A . Magallon" wrote:
>
> On 05.07 Helge Hafting wrote:

> > !0 is 1. !(anything else) is 0. It is zero and one, not
> > zero and "non-zero". So a !! construction gives zero if you have
> > zero, and one if you had anything else. There's no doubt about it.
> > >
>
> Isn't this asking for trouble with the optimizer ? It could kill both
> !!. Using that is like trusting on a certain struct padding-alignment.

No, this won't cause trouble with the optimizer, because the
optimizer isn't supposed to do _wrong_ things.

The optimizer will not remove two !! in a row, simply because that
_isn't_ a valid optimization as you just have seen.
"!" is a logical not, it isn't a bitwise not. The result of
!!(something)
is different from just (something) whenever (something) is
neither 0 or 1, the optimizer knows that very well.

Use gcc -S to get readable assembly.
Try these yourself, they compile to different code:
int main(int argc){return argc;}
int main(int argc){return !!argc;}
They have to be different, as argc >= 2 gives different results.

And try:
int main(int argc){return !argc;}
int main(int argc){return !!!argc;}

These gives the same code with or without optimization with
gcc 2.95.4 on i386, as they are equivalent. The first ! normalize
to 1 or 0, the two others are then removeable.

Helge Hafting