Blame | Last modification | View Log | RSS feed
<!-- Crown Copyright (c) 1998 -->
<HTML>
<HEAD>
<TITLE>C Checker Reference Manual: Conditional Compilation</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#400080" ALINK="#FF0000">
<A NAME=S120>
<H1>C Checker Reference Manual</H1>
<H3>January 1998</H3>
<A HREF="tdfc14.html"><IMG SRC="../images/next.gif" ALT="next section"></A>
<A HREF="tdfc12.html"><IMG SRC="../images/prev.gif" ALT="previous section"></A>
<A HREF="tdfc1.html"><IMG SRC="../images/top.gif" ALT="current document"></A>
<A HREF="../index.html"><IMG SRC="../images/home.gif" ALT="TenDRA home page">
</A>
<IMG SRC="../images/no_index.gif" ALT="document index"><P>
<HR>
<DL>
<DT><A HREF="#S121"><B>10.1 </B> - Conditional Compilation</A>
<DD>
</DL>
<HR>
<H1>10 Conditional Compilation</H1>
<A NAME=S121>
<HR><H2>10.1 Conditional Compilation</H2>
Tchk generally treats conditional compilation in the same way as other
compilers and checkers. For example, consider:<P>
<PRE>
#if expr
.... /* First branch */
#else
.... /* Second branch */
#endif
</PRE>
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. <P>
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:<P>
<PRE>
#include <stdio.h>
#include <limits.h>
int main () {
#if ( CHAR_MIN == 0 )
puts ("char is unsigned");
#else
puts ("char is signed");
#endif
return ( 0 );
}
</PRE>
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.<P>
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:<P>
<UL>
<LI>Target-dependent conditionals may not appear at the outer level.
If the checker encounters a target-dependent conditional at the outer
level an error is produced. In order to continue checking in the rest
of the file an arbitrary assumption must be made about which branch
of the conditional to process; tchk assumes that the conditional is
true and the first branch is used;<P>
<LI>The branches of allowable target-dependent conditionals may not
contain declarations or definitions.<P>
</UL>
<P>
<!-- FM pgf ignored -->
<HR>
<P><I>Part of the <A HREF="../index.html">TenDRA Web</A>.<BR>Crown
Copyright © 1998.</I></P>
</BODY>
</HTML>