Compile time assertions for gcc

David Howells dhowells@cambridge.redhat.com
Mon Apr 30 06:52:00 GMT 2001


Andi Kleen <ak@suse.de> wrote:
> I've not completed went through it, but your patch looks like you didn't
> turn off side effects for the argument expression.

I had one of the gcc engineers who work for Redhat/Cygnus (Andrey Haley) look
at it, and he said I should make sure it _did_ emit code in certain cases
(something to do with the possibility of having a volatile argument).

> Without it the assert wouldn't be a true nop.

After much wrangling here, it was decided that it should be written such that
it should return (condition_argument!=0).

This would allow you to change the assert macro from something like:

	#define assert(X) if(X) ...

to something like:

	#define assert(X) if(__builtin_ct_assertion(X,#X)) ...

David

PS: If you reply, can you check that the reply goes to
<dhowells@cambridge.redhat.com>, not <dhowells@warthog.cambridge.redhat.com>



More information about the Gcc mailing list