C preprocessor: Difference between revisions

m
[unchecked revision][unchecked revision]
Line 20:
==== Uses for debugging ====
Assertions are used to catch situations which should never happen, even under error circumstances.
#define assert(condition) do { if (!(condition)) { complain("assertion fail: (" #condition ")"); panic(); } } while(0)
assert( sizeof(struct free_memory_block) == 8 );
assert( 1 != 2 );
Line 27:
#define assert(x) do {} while(0)
Some rare unrecoverable errors should be tested for also in production code and these test should not be disabled so that we recognise the problem instead of having random crashes
#define testif(condition) do { if (!(condition)) { complain("testif fail: (" #condition ")" ); panic(); } } while(0)
testif( isChecksumCorrect( kernel_heap.first_free_list ) );
testif( timersAreOn );
Anonymous user