• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/toolchains/hndtools-armeabi-2011.09/share/doc/arm-arm-none-eabi/html/cpp/
1<html lang="en">
2<head>
3<title>If - The C Preprocessor</title>
4<meta http-equiv="Content-Type" content="text/html">
5<meta name="description" content="The C Preprocessor">
6<meta name="generator" content="makeinfo 4.13">
7<link title="Top" rel="start" href="index.html#Top">
8<link rel="up" href="Conditional-Syntax.html#Conditional-Syntax" title="Conditional Syntax">
9<link rel="prev" href="Ifdef.html#Ifdef" title="Ifdef">
10<link rel="next" href="Defined.html#Defined" title="Defined">
11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
12<!--
13Copyright (C) 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996,
141997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
152008, 2009, 2010, 2011
16Free Software Foundation, Inc.
17
18Permission is granted to copy, distribute and/or modify this document
19under the terms of the GNU Free Documentation License, Version 1.3 or
20any later version published by the Free Software Foundation.  A copy of
21the license is included in the
22section entitled ``GNU Free Documentation License''.
23
24This manual contains no Invariant Sections.  The Front-Cover Texts are
25(a) (see below), and the Back-Cover Texts are (b) (see below).
26
27(a) The FSF's Front-Cover Text is:
28
29     A GNU Manual
30
31(b) The FSF's Back-Cover Text is:
32
33     You have freedom to copy and modify this GNU Manual, like GNU
34     software.  Copies published by the Free Software Foundation raise
35     funds for GNU development.
36-->
37<meta http-equiv="Content-Style-Type" content="text/css">
38<style type="text/css"><!--
39  pre.display { font-family:inherit }
40  pre.format  { font-family:inherit }
41  pre.smalldisplay { font-family:inherit; font-size:smaller }
42  pre.smallformat  { font-family:inherit; font-size:smaller }
43  pre.smallexample { font-size:smaller }
44  pre.smalllisp    { font-size:smaller }
45  span.sc    { font-variant:small-caps }
46  span.roman { font-family:serif; font-weight:normal; } 
47  span.sansserif { font-family:sans-serif; font-weight:normal; } 
48--></style>
49<link rel="stylesheet" type="text/css" href="../cs.css">
50</head>
51<body>
52<div class="node">
53<a name="If"></a>
54<p>
55Next:&nbsp;<a rel="next" accesskey="n" href="Defined.html#Defined">Defined</a>,
56Previous:&nbsp;<a rel="previous" accesskey="p" href="Ifdef.html#Ifdef">Ifdef</a>,
57Up:&nbsp;<a rel="up" accesskey="u" href="Conditional-Syntax.html#Conditional-Syntax">Conditional Syntax</a>
58<hr>
59</div>
60
61<h4 class="subsection">4.2.2 If</h4>
62
63<p>The &lsquo;<samp><span class="samp">#if</span></samp>&rsquo; directive allows you to test the value of an arithmetic
64expression, rather than the mere existence of one macro.  Its syntax is
65
66<pre class="smallexample">     #if <var>expression</var>
67     
68     <var>controlled text</var>
69     
70     #endif /* <var>expression</var> */
71</pre>
72   <p><var>expression</var> is a C expression of integer type, subject to stringent
73restrictions.  It may contain
74
75     <ul>
76<li>Integer constants.
77
78     <li>Character constants, which are interpreted as they would be in normal
79code.
80
81     <li>Arithmetic operators for addition, subtraction, multiplication,
82division, bitwise operations, shifts, comparisons, and logical
83operations (<code>&amp;&amp;</code> and <code>||</code>).  The latter two obey the usual
84short-circuiting rules of standard C.
85
86     <li>Macros.  All macros in the expression are expanded before actual
87computation of the expression's value begins.
88
89     <li>Uses of the <code>defined</code> operator, which lets you check whether macros
90are defined in the middle of an &lsquo;<samp><span class="samp">#if</span></samp>&rsquo;.
91
92     <li>Identifiers that are not macros, which are all considered to be the
93number zero.  This allows you to write <code>#if&nbsp;MACRO<!-- /@w --></code> instead of
94<code>#ifdef&nbsp;MACRO<!-- /@w --></code>, if you know that MACRO, when defined, will
95always have a nonzero value.  Function-like macros used without their
96function call parentheses are also treated as zero.
97
98     <p>In some contexts this shortcut is undesirable.  The <samp><span class="option">-Wundef</span></samp>
99option causes GCC to warn whenever it encounters an identifier which is
100not a macro in an &lsquo;<samp><span class="samp">#if</span></samp>&rsquo;. 
101</ul>
102
103   <p>The preprocessor does not know anything about types in the language. 
104Therefore, <code>sizeof</code> operators are not recognized in &lsquo;<samp><span class="samp">#if</span></samp>&rsquo;, and
105neither are <code>enum</code> constants.  They will be taken as identifiers
106which are not macros, and replaced by zero.  In the case of
107<code>sizeof</code>, this is likely to cause the expression to be invalid.
108
109   <p>The preprocessor calculates the value of <var>expression</var>.  It carries
110out all calculations in the widest integer type known to the compiler;
111on most machines supported by GCC this is 64 bits.  This is not the same
112rule as the compiler uses to calculate the value of a constant
113expression, and may give different results in some cases.  If the value
114comes out to be nonzero, the &lsquo;<samp><span class="samp">#if</span></samp>&rsquo; succeeds and the <var>controlled
115text</var> is included; otherwise it is skipped.
116
117   </body></html>
118
119