## Printer Device Driver

[prev][next][parent][TOC]

### ASSERTT () and ASSERTF ()

The ASSERTT and ASSERTF macros are very useful to precisely locate errors in code. Each is simply a test. If the test fails, the system generates a sound, stops the program, and displays a message. The more often an ASSERTT or ASSERTF macro is used, the better the chance that the first point of failure will be captured for analysis.

Use ASSERTT or ASSERTF prior to:

Pointers Assert that pointers are nonzero.
Divisors Assert that divisors are nonzero.
Strings Assert that strings are valid.
Copying Assert that enough space is present before copying.

Use ASSERTT or ASSERTF after:

OS/2 APIs and internal functions Assert result codes of OS/2 APIs and your internal functions.

Pointers Assert pointers after allocation.

Switch statements Use ASSERTT (TRUE) in the default case of switch statements

Do not use ASSERTT or ASSERTF in:

Essential Code These macros are not included in the retail build of the product. For example, ASSERTT (0 != DosRequestMutexSem (hsem))

The following is sample output on the kernel debugger:

    Assertion failed on line 41 of file code.c

    'rc == 0'

    eax=XXXXXXXX ebx=XXXXXXXX etc=XXXXXXXX edx=XXXXXXXX esi=XXXXXXXX edi=XXXXXXXX

    eip=XXXXXXXX esp=XXXXXXXX ebp=XXXXXXXX iopl=2 -- -- -- xx xx xx xx xx xx xx xx

    cs=XXXX ss=XXXX ds=XXXX es=XXXX fs=XXXX gs=XXXX  cr2=XXXXXXXX cr3=XXXXXXXX

    program:CODE32:BREAKPOINT

    XXXX:XXXXXXXX cc                 int    3

    ##

Use ASSERTT and ASSERTF under the following conditions:

ASSERTT (z); where z is a Boolean expression that should evaluate to zero or FALSE on success.

ASSERTF (nz); where nz is a Boolean expression that should evaluate to nonzero or TRUE on success.

The following example shows how to use ASSERTT and ASSERTF:

    pointer = NULL;

    rc = DosAllocMem( &pointer, size, PAG_EXECUTE | PAG_READ | PAG_WRITE );

    ASSERTT (rc);       // Return code should be zero (success)

    ASSERTF (pointer);  // Pointer should be nonzero