• 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>Conditionals - 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="prev" href="Macros.html#Macros" title="Macros">
9<link rel="next" href="Diagnostics.html#Diagnostics" title="Diagnostics">
10<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
11<!--
12Copyright (C) 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996,
131997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
142008, 2009, 2010, 2011
15Free Software Foundation, Inc.
16
17Permission is granted to copy, distribute and/or modify this document
18under the terms of the GNU Free Documentation License, Version 1.3 or
19any later version published by the Free Software Foundation.  A copy of
20the license is included in the
21section entitled ``GNU Free Documentation License''.
22
23This manual contains no Invariant Sections.  The Front-Cover Texts are
24(a) (see below), and the Back-Cover Texts are (b) (see below).
25
26(a) The FSF's Front-Cover Text is:
27
28     A GNU Manual
29
30(b) The FSF's Back-Cover Text is:
31
32     You have freedom to copy and modify this GNU Manual, like GNU
33     software.  Copies published by the Free Software Foundation raise
34     funds for GNU development.
35-->
36<meta http-equiv="Content-Style-Type" content="text/css">
37<style type="text/css"><!--
38  pre.display { font-family:inherit }
39  pre.format  { font-family:inherit }
40  pre.smalldisplay { font-family:inherit; font-size:smaller }
41  pre.smallformat  { font-family:inherit; font-size:smaller }
42  pre.smallexample { font-size:smaller }
43  pre.smalllisp    { font-size:smaller }
44  span.sc    { font-variant:small-caps }
45  span.roman { font-family:serif; font-weight:normal; } 
46  span.sansserif { font-family:sans-serif; font-weight:normal; } 
47--></style>
48<link rel="stylesheet" type="text/css" href="../cs.css">
49</head>
50<body>
51<div class="node">
52<a name="Conditionals"></a>
53<p>
54Next:&nbsp;<a rel="next" accesskey="n" href="Diagnostics.html#Diagnostics">Diagnostics</a>,
55Previous:&nbsp;<a rel="previous" accesskey="p" href="Macros.html#Macros">Macros</a>,
56Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a>
57<hr>
58</div>
59
60<h2 class="chapter">4 Conditionals</h2>
61
62<p><a name="index-conditionals-83"></a>
63A <dfn>conditional</dfn> is a directive that instructs the preprocessor to
64select whether or not to include a chunk of code in the final token
65stream passed to the compiler.  Preprocessor conditionals can test
66arithmetic expressions, or whether a name is defined as a macro, or both
67simultaneously using the special <code>defined</code> operator.
68
69   <p>A conditional in the C preprocessor resembles in some ways an <code>if</code>
70statement in C, but it is important to understand the difference between
71them.  The condition in an <code>if</code> statement is tested during the
72execution of your program.  Its purpose is to allow your program to
73behave differently from run to run, depending on the data it is
74operating on.  The condition in a preprocessing conditional directive is
75tested when your program is compiled.  Its purpose is to allow different
76code to be included in the program depending on the situation at the
77time of compilation.
78
79   <p>However, the distinction is becoming less clear.  Modern compilers often
80do test <code>if</code> statements when a program is compiled, if their
81conditions are known not to vary at run time, and eliminate code which
82can never be executed.  If you can count on your compiler to do this,
83you may find that your program is more readable if you use <code>if</code>
84statements with constant conditions (perhaps determined by macros).  Of
85course, you can only use this to exclude code, not type definitions or
86other preprocessing directives, and you can only do it if the code
87remains syntactically valid when it is not to be used.
88
89   <p>GCC version 3 eliminates this kind of never-executed code even when
90not optimizing.  Older versions did it only when optimizing.
91
92<ul class="menu">
93<li><a accesskey="1" href="Conditional-Uses.html#Conditional-Uses">Conditional Uses</a>
94<li><a accesskey="2" href="Conditional-Syntax.html#Conditional-Syntax">Conditional Syntax</a>
95<li><a accesskey="3" href="Deleted-Code.html#Deleted-Code">Deleted Code</a>
96</ul>
97
98   </body></html>
99
100