 
    
<?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>defined Archives - Complete, Concrete, Concise</title>
	<atom:link href="https://complete-concrete-concise.com/tag/defined/feed/" rel="self" type="application/rss+xml" />
	<link>https://complete-concrete-concise.com/tag/defined/</link>
	<description>Practical Information Without The Bloat</description>
	<lastBuildDate>Wed, 06 Jul 2011 16:39:47 +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 – Understanding the defined Operator</title>
		<link>https://complete-concrete-concise.com/programming/c/preprocessor-understanding-the-defined-operator/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Wed, 06 Jul 2011 16:39:47 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[defined]]></category>
		<category><![CDATA[preprocessor]]></category>
		<category><![CDATA[understanding]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=870</guid>

					<description><![CDATA[<p>This is the least known of the preprocessor operators. The other two operators are the token pasting operator (##) and the stringizing operator (#). The behaviour is the same for both C and C++ compilers. Format defined macro_name or defined ( macro_name ) Use The defined operator is used to check if a macro_name has [&#8230;]</p>
<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-understanding-the-defined-operator/">Preprocessor – Understanding the defined Operator</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 is the least known of the preprocessor operators. The other two operators are the token pasting operator (<code>##</code>) and the stringizing operator (<code>#</code>).</p>
<p>The behaviour is the same for both C and C++ compilers.</p>
</div>
<h1>Format</h1>
<pre><strong>defined</strong> <em>macro_name</em>
<p> or</p>
<strong>defined</strong> ( <em>macro_name</em> )</pre>
<h1>Use</h1>
<p>The <code>defined</code> operator is used to check if a <code><em>macro_name</em></code> has been defined or not. If the <code><em>macro_name</em></code> exists, it does not evaluate the macro.</p>
<p>If the <code><em>macro_name</em></code> exists, then <span class="i1"><code><strong>defined</strong> <em>macro_name</em></code></span> is replaced with the value 1 (one), otherwise, it is replaced with the value 0 (zero).</p>
<p>The <code>defined</code> operator may only be used with the <code>#if</code> and <code>#elif</code> preprocessor directives.</p>
<p>The expression:</p>
<pre>#if defined MY_MACRO</pre>
<p>has the same effect as:</p>
<pre>#ifdef MY_MACRO</pre>
<p>The expression:</p>
<pre>#if !defined MY_MACRO</pre>
<p>has the same effect as:</p>
<pre>#ifndef MY_MACRO</pre>
<p>The expression:</p>
<pre>#if defined MY_MACRO && defined MY_OTHER_MACRO</pre>
<p>has the same effect as:</p>
<pre>#ifdef MY_MACRO
# ifdef MY_OTHER_MACRO</pre>
<p>The following expression is much harder to express cleanly using <code>#ifdef</code> or <code>#ifndef</code> directives:</p>
<pre>#if defined MY_MACRO || defined MY_OTHER_MACRO</pre>
<p>A possible way to express it using <code>#ifdef</code> would be:</p>
<pre>
// if MY_MACRO exists, we don't care about MY_OTHER_MACRO
#ifdef MY_MACRO
.
.
.
// statements to process
.
.
.
#endif
// if MY_MACRO doesn't exist, then we need to check
// if MY_OTHER_MACRO exists
#ifndef MY_MACRO
# ifdef MY_OTHER_MACRO
.
.
.
//duplicate statements to process
.
.
.
#endif</pre>
</p>
<p>Which results in duplicated statements. This means the code is more prone to errors changes in one piece of code must be made in other places.</p>

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