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