Re: [PATCH] *(int*)0 = 0 & variations

Jamie Lokier (lkd@tantalophile.demon.co.uk)
Tue, 29 Jun 1999 04:05:10 +0200


Stefan Monnier wrote:
> > Assertions should not have side effects -- if you write them right, GCC
> > will optimise away the expression anyway. (Ignore strings for the moment).
>
> If they have no side-effect, then there is no point in evaluating them with
> NDEBUG set. Please, let's not try to hide bugs.

If they have no side-effect, they'll compile to *NO CODE*.
It doesn't matter what kassert does in this case.

> PS: if they do have side-effects, then they are bogus.

They are indeed. Ideally we'd like a GCC __builtin_no_side_effects() to
warn us about expressions with side effects.

Away from the ideal.. assert() has been noted as a cause of subtle bugs
over the years by many folks. Somehow the fact that `assert' is
different from `any_other_function' seems to pass by a programmer's
mental pattern matching.

It's easy to write correct assert() calls.
But it can be damn hard to spot other peoples' bogus ones.

-- Jamie

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/