C Checker Reference Manual

January 1998

next section previous section current document TenDRA home page document index

10.1 - Conditional Compilation

10 Conditional Compilation

10.1 Conditional Compilation

Tchk generally treats conditional compilation in the same way as other compilers and checkers. For example, consider:

	#if expr
	.... /* First branch */
	.... /* Second branch */
the expression, expr, is evaluated: if it is non-zero the first branch of the conditional is processed; if it is zero the second branch is processed instead.

Sometimes, however, tchk may be unable to evaluate the expression statically because of the abstract types and expressions which arise from the minimum integer range assumptions or the abstract standard headers used by the tool (see target-dependent types in section 4.5). For example, consider the following ISO compliant program:

	#include <stdio.h>
	#include <limits.h>
	int main () {
	#if ( CHAR_MIN == 0 )
		puts ("char is unsigned");
		puts ("char is signed");
		return ( 0 );
The TenDRA representation of the ISO API merely states that CHAR_MIN - the least value which fits into a char - is a target dependent integral constant. Hence, whether or not it equals zero is again target dependent, so the checker needs to maintain both branches. By contrast, any conventional compiler is compiling to a particular target machine on which CHAR_MIN is a specific integral constant. It can therefore always determine which branch of the conditional it should compile.

In order to allow both branches to be maintained in these cases, it has been necessary for tchk to impose certain restrictions on the form of the conditional branches and the positions in which such target-dependent conditionals may occur. These may be summarised as:

Part of the TenDRA Web.
Crown Copyright © 1998.