2 |
7u83 |
1 |
<!-- Crown Copyright (c) 1998 -->
|
|
|
2 |
<HTML>
|
|
|
3 |
<HEAD>
|
|
|
4 |
<TITLE>C Checker Reference Manual: Conditional Compilation</TITLE>
|
|
|
5 |
</HEAD>
|
|
|
6 |
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#400080" ALINK="#FF0000">
|
|
|
7 |
<A NAME=S120>
|
|
|
8 |
<H1>C Checker Reference Manual</H1>
|
|
|
9 |
<H3>January 1998</H3>
|
|
|
10 |
<A HREF="tdfc14.html"><IMG SRC="../images/next.gif" ALT="next section"></A>
|
|
|
11 |
<A HREF="tdfc12.html"><IMG SRC="../images/prev.gif" ALT="previous section"></A>
|
|
|
12 |
<A HREF="tdfc1.html"><IMG SRC="../images/top.gif" ALT="current document"></A>
|
|
|
13 |
<A HREF="../index.html"><IMG SRC="../images/home.gif" ALT="TenDRA home page">
|
|
|
14 |
</A>
|
|
|
15 |
<IMG SRC="../images/no_index.gif" ALT="document index"><P>
|
|
|
16 |
<HR>
|
|
|
17 |
<DL>
|
|
|
18 |
<DT><A HREF="#S121"><B>10.1 </B> - Conditional Compilation</A>
|
|
|
19 |
<DD>
|
|
|
20 |
</DL>
|
|
|
21 |
|
|
|
22 |
<HR>
|
|
|
23 |
<H1>10 Conditional Compilation</H1>
|
|
|
24 |
<A NAME=S121>
|
|
|
25 |
<HR><H2>10.1 Conditional Compilation</H2>
|
|
|
26 |
Tchk generally treats conditional compilation in the same way as other
|
|
|
27 |
compilers and checkers. For example, consider:<P>
|
|
|
28 |
<PRE>
|
|
|
29 |
#if expr
|
|
|
30 |
.... /* First branch */
|
|
|
31 |
#else
|
|
|
32 |
.... /* Second branch */
|
|
|
33 |
#endif
|
|
|
34 |
</PRE>
|
|
|
35 |
the expression, expr, is evaluated: if it is non-zero the first branch
|
|
|
36 |
of the conditional is processed; if it is zero the second branch is
|
|
|
37 |
processed instead. <P>
|
|
|
38 |
Sometimes, however, tchk may be unable to evaluate the expression
|
|
|
39 |
statically because of the abstract types and expressions which arise
|
|
|
40 |
from the minimum integer range assumptions or the abstract standard
|
|
|
41 |
headers used by the tool (see target-dependent types in section 4.5).
|
|
|
42 |
For example, consider the following ISO compliant program:<P>
|
|
|
43 |
<PRE>
|
|
|
44 |
#include <stdio.h>
|
|
|
45 |
#include <limits.h>
|
|
|
46 |
int main () {
|
|
|
47 |
#if ( CHAR_MIN == 0 )
|
|
|
48 |
puts ("char is unsigned");
|
|
|
49 |
#else
|
|
|
50 |
puts ("char is signed");
|
|
|
51 |
#endif
|
|
|
52 |
return ( 0 );
|
|
|
53 |
}
|
|
|
54 |
</PRE>
|
|
|
55 |
The TenDRA representation of the ISO API merely states that CHAR_MIN
|
|
|
56 |
- the least value which fits into a char - is a target dependent integral
|
|
|
57 |
constant. Hence, whether or not it equals zero is again target dependent,
|
|
|
58 |
so the checker needs to maintain both branches. By contrast, any conventional
|
|
|
59 |
compiler is compiling to a particular target machine on which CHAR_MIN
|
|
|
60 |
is a specific integral constant. It can therefore always determine
|
|
|
61 |
which branch of the conditional it should compile.<P>
|
|
|
62 |
In order to allow both branches to be maintained in these cases, it
|
|
|
63 |
has been necessary for tchk to impose certain restrictions on the
|
|
|
64 |
form of the conditional branches and the positions in which such target-dependent
|
|
|
65 |
conditionals may occur. These may be summarised as:<P>
|
|
|
66 |
<UL>
|
|
|
67 |
<LI>Target-dependent conditionals may not appear at the outer level.
|
|
|
68 |
If the checker encounters a target-dependent conditional at the outer
|
|
|
69 |
level an error is produced. In order to continue checking in the rest
|
|
|
70 |
of the file an arbitrary assumption must be made about which branch
|
|
|
71 |
of the conditional to process; tchk assumes that the conditional is
|
|
|
72 |
true and the first branch is used;<P>
|
|
|
73 |
<LI>The branches of allowable target-dependent conditionals may not
|
|
|
74 |
contain declarations or definitions.<P>
|
|
|
75 |
</UL>
|
|
|
76 |
<P>
|
|
|
77 |
<!-- FM pgf ignored -->
|
|
|
78 |
<HR>
|
|
|
79 |
<P><I>Part of the <A HREF="../index.html">TenDRA Web</A>.<BR>Crown
|
|
|
80 |
Copyright © 1998.</I></P>
|
|
|
81 |
</BODY>
|
|
|
82 |
</HTML>
|