/* * assrtest — exercise from SDCC's z80.lib. * * Tests both the disabled-debug (NDEBUG) form and the active form. * The failing assert at the end prints an error message via printf * (which routes through our putchar) and then halts. */ #include #include static int divide(int a, int b) { assert(b != 0); /* must succeed for the test cases */ return a / b; } int main(int argc, char **argv) { (void)argc; (void)argv; puts("assrtest: exercising "); /* These pass. */ int q = divide(10, 2); printf(" divide(10, 2) = %d\n", q); assert(q == 5); q = divide(-9, 3); printf(" divide(-9, 3) = %d\n", q); assert(q == -3); puts(" all passing asserts OK"); /* Final, failing assert. Prints "Assert(...) failed in function ..." * then enters an infinite loop (SDCC __assert convention). */ puts(" triggering deliberate failing assert (system will hang)..."); int zero = 0; (void)divide(1, zero); /* unreachable */ return 0; }