 
    
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>#elif Archives - Complete, Concrete, Concise</title>
	<atom:link href="https://complete-concrete-concise.com/tag/elif/feed/" rel="self" type="application/rss+xml" />
	<link>https://complete-concrete-concise.com/tag/elif/</link>
	<description>Practical Information Without The Bloat</description>
	<lastBuildDate>Wed, 13 Jul 2011 10:31:26 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
	<item>
		<title>Preprocessor – the #elif Directive</title>
		<link>https://complete-concrete-concise.com/programming/c/preprocessor-the-elif-directive/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Wed, 13 Jul 2011 10:31:26 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[#elif]]></category>
		<category><![CDATA[preprocessor]]></category>
		<category><![CDATA[understanding]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=897</guid>

					<description><![CDATA[<p>This (along with the #if directive) is probably the second most complicated preprocessor directive because the controlling expression can be complex and include tricky macro replacements. #elif is one of five preprocessor selection statements allowing selection of alternative sections of code for compilation. The other four selection statements are: #ifdef, #ifndef, #if, and #else. Behaviour [&#8230;]</p>
<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-the-elif-directive/">Preprocessor – the #elif Directive</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="c1">
<p>This (along with the <code>#if</code> directive) is probably the second most complicated preprocessor directive because the <em>controlling expression</em> can be complex and include tricky macro replacements.</p>
<p><code>#elif</code> is one of five preprocessor selection statements allowing selection of alternative sections of code for compilation. The other four selection statements are: <code>#ifdef</code>, <code>#ifndef</code>, <code>#if</code>, and <code>#else</code>.</p>
<p>Behaviour of this preprocessor directive is the same for both C and C++ compilers.</p>
<p>An identifier is a sequence of letters, numbers and underscore characters. Identifiers must begin with a letter or underscore character. </p>
</div>
<h1>Purpose</h1>
<p>The <code>#elif</code> directive controls whether the statements found between it and a terminating <code>#endif</code>, <code>#else</code>, or <code>#elif</code> directive are compiled or skipped. The decision is based on the value of the controlling expression.</p>
<p>It is used to allow creating more complex code selection blocks, featuring more alternatives.</p>
<h1>Format </h1>
<div class="c2">
<p><strong>#if</strong> or <strong>#ifdef</strong> or <strong>#ifndef</strong></p>
<p>preprocessor or code statements</p>
<p><strong>#elif</strong> <em>controlling_expression</em></p>
<p>preprocessor or code statements</p>
<p><strong>#endif</strong>, <strong>#elif</strong>, or <strong>#else</strong></p>
</div>
<p>All preprocessor directives begin with the <code>#</code> symbol. It must be the first character on the line or the first character on the line following optional white space. </p>
<div class="c4">
<p>Some early compilers flagged an error if <code>#</code> was not the first character on the line.</p>
</div>
<p>Spaces or tabs are permitted between the <code>#</code> and <code>elif</code>, but not escape characters or other symbols or macros. The preprocessor removes white space and concatenates the <code>#</code> and <code>elif</code> together.</p>
<p>The following are valid uses:</p>
<pre>#elif defined my_macro
# elif defined my_macro;
# elif defined my_macro
# /* comments are white space */ elif defined my_macro</pre>
<p>The following are invalid uses:</p>
<pre>// #\ is not a valid preprocessor directive
# \t elif defined my_macro
// #" is not a valid preprocessor directive
# "" elif defined my_macro</pre>
<h1>Rules for the Controlling Expression</h1>
<p>The <em>controlling_expression</em> must be made up of: integers, identifiers, macros, character literals, operators, or the preprocessor operator <code>defined</code>. Strings, floating point values, preprocessor directives, the token pasting operator (##), and stringizing operator (#) are invalid and the program is malformed.</p>
<p>The <em>controlling_expression</em> must evaluate to an integer value.</p>
<p>If the <em>controlling expression</em> is non-zero (TRUE), then the statements following the <code>#elif</code> until the end of the block (<code>#endif</code>, <code>#elif</code>, or <code>#else</code>) are compiled. </p>
<pre> #if 0
.
.
.
// because the controlling expression is zero (FALSE) everything
// until the end of the current block (#elif 42) will be skipped
.
.
.
#elif 42
.
.
.
// because everything in the first block was skipped, and this
// controlling expression evaluates to non-zero (TRUE), all the
// statements until the end of the current block (#else) will be
// compiled.
.
.
.
#else
.
.
.
// all the statements here are skipped because the statements in
// the previous block were compiled
.
.
.
#endif</pre>
<p>If the <em>controlling expression</em> is zero (FALSE), then the statements following the <code>#elif</code> until the end of the block (<code>#endif</code>, <code>#elif</code>, or <code>#else</code>) are skipped. </p>
<p>Integers can be <code>signed</code> or <code>unsigned</code> and have a minimum range equal to <code>long</code> and <code>unsigned long</code> integers, respectively.</p>
<p>Identifiers that are macro names are expanded and evaluated and their evaluation value replaces the macro name.</p>
<p>If the macro name is evaluated by the <code>defined</code> operator, then it is not expanded:</p>
<pre>#define MY_MACRO "twas brillig"
// MY_MACRO will never be expanded or evaluated.
// the defined operator determines if the identifier MY_MACRO
// exists. It returns 1 if the macro is defined or 0 if the macro is
// not defined.
#if 0
// everything in here is skipped
#elif defined MY_MACRO
// code in here will only be compiled if MY_MACRO exists
#endif</pre>
<p>Identifiers that are not macro names, are replaced with a value of 0 (zero):</p>
<pre>#elif SOME_RANDOM_IDENTIFIER</pre>
<p>If the identifier <code>SOME_RANDOM_IDENTIFIER</code> was never defined using <code>#define</code> or was undefined (before its use) using <code>#undef</code>, then it is assigned the value of 0 (zero). To the preprocessor, it looks like: </p>
<pre>#elif 0</pre>
<p>Character literals are converted into integer values. The value of a character literal appearing in either <code>#if</code> or <code>#elif</code> does not have to be the same as the value a character literal would have in a code expression. This is because the character set used by the preprocessor does not have to be the same as the character set used by the compiler.</p>
<p>Depending on the compiler, character literals may or may not be permitted to have negative values.</p>
<p>Any of the arithmetic, relational, logical, or bitwise operators may be used in the <em>controlling_expression</em>. Evaluation precedence is the same as for the language. </p>
<p><code>#elif</code> never begins a selection block, it is always used as an alternative selection following a previous <code>#if</code>, <code>#ifdef</code>, <code>#ifndef</code>, or <code>#elif</code> preprocessor directive.</p>

<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-the-elif-directive/">Preprocessor – the #elif Directive</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
