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

Horst von Brand (vonbrand@inf.utfsm.cl)
Wed, 23 Jun 1999 13:12:20 -0400


adve@oce.nl (Arjan van de Ven) said:
> Riley Williams had the wisdom to write:
> RW> +#ifdef DEBUG
> RW> +#define kassert(cond) if (!(cond)) \
> RW> + printk(KERN_DEBUG "ASSERTION FAILURE: %s line %u: %s\n", \
> RW> + __FILE__, __LINE__, "cond")
> RW> +#else
> RW> +#define kassert(cond)
> RW> +#endif

> Please modify the second kassert to
>
>
> #define kassert(cond) if (cond) ;
>
> That way,
>
> kassert(var++)
>
> works the same with and without DEBUG.
>
> (I know, one shouldn't change a variable in an assert, but there is NO
> decent way to find such bugs)

Better write:

do { (void)(cond); } while(0)

then (your if can screw up other ifs).

--
Dr. Horst H. von Brand                       mailto:vonbrand@inf.utfsm.cl
Departamento de Informatica                     Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria              +56 32 654239
Casilla 110-V, Valparaiso, Chile                Fax:  +56 32 797513

- 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/