1<html lang="en"> 2<head> 3<title>Defined - 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="If.html#If" title="If"> 10<link rel="next" href="Else.html#Else" title="Else"> 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="Defined"></a> 54<p> 55Next: <a rel="next" accesskey="n" href="Else.html#Else">Else</a>, 56Previous: <a rel="previous" accesskey="p" href="If.html#If">If</a>, 57Up: <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.3 Defined</h4> 62 63<p><a name="index-g_t_0040code_007bdefined_007d-89"></a>The special operator <code>defined</code> is used in ‘<samp><span class="samp">#if</span></samp>’ and 64‘<samp><span class="samp">#elif</span></samp>’ expressions to test whether a certain name is defined as a 65macro. <code>defined </code><var>name</var> and <code>defined (</code><var>name</var><code>)</code> are 66both expressions whose value is 1 if <var>name</var> is defined as a macro at 67the current point in the program, and 0 otherwise. Thus, <code>#if defined MACRO<!-- /@w --></code> is precisely equivalent to <code>#ifdef MACRO<!-- /@w --></code>. 68 69 <p><code>defined</code> is useful when you wish to test more than one macro for 70existence at once. For example, 71 72<pre class="smallexample"> #if defined (__vax__) || defined (__ns16000__) 73</pre> 74 <p class="noindent">would succeed if either of the names <code>__vax__</code> or 75<code>__ns16000__</code> is defined as a macro. 76 77 <p>Conditionals written like this: 78 79<pre class="smallexample"> #if defined BUFSIZE && BUFSIZE >= 1024 80</pre> 81 <p class="noindent">can generally be simplified to just <code>#if BUFSIZE >= 1024<!-- /@w --></code>, 82since if <code>BUFSIZE</code> is not defined, it will be interpreted as having 83the value zero. 84 85 <p>If the <code>defined</code> operator appears as a result of a macro expansion, 86the C standard says the behavior is undefined. GNU cpp treats it as a 87genuine <code>defined</code> operator and evaluates it normally. It will warn 88wherever your code uses this feature if you use the command-line option 89<samp><span class="option">-pedantic</span></samp>, since other compilers may handle it differently. 90 91 </body></html> 92 93