 
    
<?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>preprocessor Archives - Complete, Concrete, Concise</title>
	<atom:link href="https://complete-concrete-concise.com/tag/preprocessor/feed/" rel="self" type="application/rss+xml" />
	<link>https://complete-concrete-concise.com/tag/preprocessor/</link>
	<description>Practical Information Without The Bloat</description>
	<lastBuildDate>Thu, 21 Jul 2011 01:34:12 +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>How to Add Comments to Macros</title>
		<link>https://complete-concrete-concise.com/programming/c/how-to-add-comments-to-macros/</link>
					<comments>https://complete-concrete-concise.com/programming/c/how-to-add-comments-to-macros/#comments</comments>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Thu, 21 Jul 2011 01:34:12 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[preprocessor]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=931</guid>

					<description><![CDATA[<p>Comments are an important part of documenting your code. Adding comments to macros is quite easy, but it has to be done the right way. This works with both C and C++ compilers. The easiest way to document macros is to just add comments before or after the macro definition: // returns the larger of [&#8230;]</p>
<p>The post <a href="https://complete-concrete-concise.com/programming/c/how-to-add-comments-to-macros/">How to Add Comments to Macros</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="c1">
<p>Comments are an important part of documenting your code.</p>
<p>Adding comments to macros is quite easy, but it has to be done the right way.</p>
<p>This works with both C and C++ compilers.</p>
</div>
<p>The easiest way to document macros is to just add comments before or after the macro definition:</p>
<pre>// returns the larger of the two arguments
#define MAX(x, y) (x)>(y)?(x):(y)</pre>
<p>This works well for small macros, but if you have a larger macro that is spread over several lines, it might be nice to put comments nearer some tricky or crucial bit of code. You can do that by using C-style comments (<code>/**/</code>). The preprocessor treats comments as white space, so comments of the form <code>/* some sort of comment */</code> are treated as white space.</p>
<pre>#define TRANS_TEST(a, b, c) \
{  <strong class="i2"> /* variables to store intermediate results*/</strong> \
    bool aGb = false;\
    bool bGc = false;\
    if (a > b) \
    {\
        aGb = true;
        printf("'a' is larger than 'b'\n");\
    }\
    if (b > c) \
    {\
        bGc = true;
        printf("'b' is larger than 'c'\n");\
    }\
    <strong class="i2">/* do the transitivity test */</strong> \
    if (aGb &&  bGc) \
    {\
        printf("by transitivity we know 'a' is larger than 'c'\n");\
    }\
}</pre>
<p>The above (contrived) example, determines if parameter <code>a</code> is greater than parameter <code>c</code> by using the principle of transitivity.</p>
<p>C style comments were used to document the code. Note the line splicing (<code>\</code>) operator appears at the end of each line.</p>
<p>When this code is compiled, the preprocessor will treat the comment (and any white space surrounding it) as white space.</p>
<p>NOTE: Using C++ single line comments (<code>//</code>)won&#8217;t work because everything following the <code>//</code> until the end of the line is considered white space. Even if the macro is <em>spread over several lines</em> using the line splicing (<code>\</code>) operator, the preprocessor turns it into a single line and everything following the <code>//</code> will be considered part of the comment (hence, white space).</p>
<pre>#define TRANS_TEST(a, b, c) \
{   <strong class="i2">// variables to store intermediate results</strong> \
    bool aGb = false;\
    bool bGc = false;\
    if (a > b) \
    {\
        aGb = true;
        printf("'a' is larger than 'b'\n");\
    }\
    if (b > c) \
    {\
       bGc = true;
       printf("'b' is larger than 'c'\n");\
    }\
    <strong class="i2">// do the transitivity test</strong>  \
    if (aGb &&  bGc) \
    {\
        printf("by transitivity we know 'a' is larger than 'c'\n");\
    }\
}</pre>
<p>In the above example, the C++ single line comment was used. When it is processed by the preprocessor, everything until the end of the line (after all the lines have been spliced together) will be considered a comment. Consequently, the compiler will issue an error because all it will see is:</p>
<pre><p>#define TRANS_TEST(a, b, c) {</p></pre>

<p>The post <a href="https://complete-concrete-concise.com/programming/c/how-to-add-comments-to-macros/">How to Add Comments to Macros</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://complete-concrete-concise.com/programming/c/how-to-add-comments-to-macros/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>Preprocessor &#8211; the #error Directive</title>
		<link>https://complete-concrete-concise.com/programming/c/preprocessor-the-error-directive/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Wed, 20 Jul 2011 08:04:02 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[preprocessor]]></category>
		<category><![CDATA[understanding]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/programming/c/927</guid>

					<description><![CDATA[<p>Preprocessor &#8211; the #error Directive This is a very useful and often underused preprocessor directive. Behaviour of this preprocessor directive is the same for both C and C++ compilers. Purpose The #error directive terminates compilation and outputs the text following the directive. Format #error text All preprocessor directives begin with the # symbol. It must [&#8230;]</p>
<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-the-error-directive/">Preprocessor &#8211; the #error Directive</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Preprocessor &#8211; the #error Directive</p>
<div class="c1">
<p>This is a very useful and often underused preprocessor directive.</p>
<p>Behaviour of this preprocessor directive is the same for both C and C++ compilers.</p>
</div>
<h1>Purpose</h1>
<p>The <code>#error</code> directive terminates compilation and outputs the text following the directive.</p>
<h1>Format </h1>
<pre><strong>#error</strong> <em>text</em></pre>
<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>error</code>, but not escape characters or other symbols or macros. The preprocessor removes white space and concatenates the <code>#</code> and <code>error</code> together.</p>
<p>If anything follows the <code>#error</code> directive (other than white space) then the program is malformed.</p>
<p>The following are valid uses:</p>
<pre>#error some error message text
# error some error text to display
# /* comments are white space */ error some error message to display</pre>
<p>The following are invalid uses:</p>
<pre>// #\ is not a valid preprocessor directive
# \t error text to output
// #" is not a valid preprocessor directive
# "" text to output</pre>
<h1>Use</h1>
<p>It is used to render a program malformed and output the text following the <code>#error</code> directive. The text may be quoted or unquoted (it doesn&#8217;t matter). No macro expansion takes place.</p>
<div class="c2">
<p>The language specifications do not say how the text following the <code>#error</code> directive is to be treated.</p>
<p>The GCC compiler, replaces all white space characters between tokens with a single white space character.</p>
<p>I have no reason to believe other compilers behave differently since white space is not considered significant in the C and C++ languages &#8211; it serves only to seperate tokens from one another.</p>
</div>
<p>There are many times when it is useful to halt compilation:</p>
<ol>
<li>code is incomplete</li>
<li>code requires particular library versions</li>
<li>code uses compiler dependent features</li>
<li>code has specific compiler requirements</li>
</ol>
<h2>Incomplete Code</h2>
<p>When developing code, it is common to create stub functions. For the final release, these stub functions need to be implemented. We can let the compiler help us catch unimplemented functions:</p>
<pre><p>int my_function( void )</p>
<p>{</p>
<p> #error my_function not implemented</p>
<p> return 0;</p>
<p>}</p></pre>
<p>The above code will fail for every compile. It might be more useful to allow compiling during development, but break the compile when we try to compile a release version. In the following example, we assume that during development, the macro <code>DEBUG</code> is defined:</p>
<pre><p>int my_function( void )</p>
<p>{</p>
<p>#ifndef DEBUG</p>
<p> #error my_function not implemented</p>
<p>#endif
<p> return 0;</p>
<p>}</p></pre>
<p>During development, we can compile the code, but when we do a release build (one in which <code>DEBUG</code> is not defined, then we catch unimplemented functions.</p>
<h2>Version Checking</h2>
<p>Sometimes code is dependent on particular versions of a library. It is useful to be able to stop compilation if an incorrect library version is included:</p>
<pre><p>#if library_version < 2</p>
<p>#error requires library_version 2 or better</p>
<p>#endif</p></pre>
<h2>Compiler Dependency</h2>
<p>Sometimes, code uses compiler specific features (for example, GCC allows nesting a <code>#define</code> within another <code>#define</code> &#8211; this is a non-standard compiler feature).</p>
<pre>#ifdef __GCC__
<p>// some GCC specific code goes here</p>
<p>#else</p>
<p>#error requires GCC compiler to compile</p>
<p>#endif</p></pre>
<h2>Compiler Requirements</h2>
<p>Sometimes code makes relies on certain assumptions about the target environment (for example, the size of an integer):</p>
<pre><p>#include <limits.h></p>
<p>#if UINT_MAX != 4294967295</p>
<p> #error this application requires 32 bit integers</p>
<p>#endif</p></pre>

<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-the-error-directive/">Preprocessor &#8211; the #error Directive</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Preprocessor – the #line Directive</title>
		<link>https://complete-concrete-concise.com/programming/c/preprocessor-the-line-directive/</link>
					<comments>https://complete-concrete-concise.com/programming/c/preprocessor-the-line-directive/#comments</comments>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Tue, 19 Jul 2011 13:46:30 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[#line]]></category>
		<category><![CDATA[preprocessor]]></category>
		<category><![CDATA[understanding]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=925</guid>

					<description><![CDATA[<p>I don&#8217;t think I have ever seen this directive used. Behaviour of this preprocessor directive is the same for both C and C++ compilers. Purpose The #line directive allows setting the current line number and name of the file being compiled. Format #line integer or #line integer "file_name" or #line preprocessing_expression All preprocessor directives begin [&#8230;]</p>
<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-the-line-directive/">Preprocessor – the #line 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>I don&#8217;t think I have ever seen this directive used.</p>
<p>Behaviour of this preprocessor directive is the same for both C and C++ compilers.</p>
</div>
<h1>Purpose</h1>
<p>The <code>#line</code> directive allows setting the current line number and  name of the file being compiled.</p>
<h1>Format </h1>
<pre><p><strong>#line</strong> <em>integer</em><p>
<p>or</p>
<p><strong>#line</strong> <em>integer</em> <em>"file_name"</em></p>
<p>or</p>
<p><strong>#line</strong> <em>preprocessing_expression</em></p></pre>
<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>line</code>, but not escape characters or other symbols or macros. The preprocessor removes white space and concatenates the <code>#</code> and <code>line</code> together.</p>
<p>If anything follows the <code>#line</code> directive (other than white space) then the program is malformed.</p>
<p>The following are valid uses:</p>
<pre>#line 100
# line   100
# /* comments are white space */ line 100</pre>
<p>The following are invalid uses:</p>
<pre>// #\ is not a valid preprocessor directive
# \t line 100
// #" is not a valid preprocessor directive
# "" line 100</pre>
<h1>Use</h1>
<p>There are three different forms of the <code>#line</code> directive which allow you to change the current line numbering and file name during preprocessing.</p>
<h2>First Form &#8211; #line <em>integer</em></h2>
<p>When the line number is changed, the line immediately <u>following</u> the <code>#line</code> directive receives the new line number:</p>
<pre>#line 123
/* this line is now line number 123 */
/* this line is line number 124 */
/* this line is line number 126 */</pre>
<div class="c2">
<p>For C89/C90 and C++97, the valid range of values for the line number is from 1 to 32767 (0x0001 to 0x7FFF).</p>
<p>In C99 and the upcoming C++0x, the valid range of values for the line number is from 1 to 2147483648 (0x00000001 to 0x7FFFFFFF).</p>
<p>How the compiler deals with out of range values is undefined. Some compilers may accept them, others may issue a warning or error.</p>
</div>
<h2>Second Form &#8211; #line <em>integer</em> <em>file_name</em></h2>
<p>When <em>file_name</em> is specified, the working name of the file being compiled is changed to the specified string. The <em>file_name</em> must be enclosed by double quotes (<code>"</code>).</p>
<p>In the following example, the line number remains the same but the name of the file being compiled is changed to <code>new_file_name.abc</code>. Only the name the compiler thinks it is compiling changes (and which it will return using the <code>__FILE__</code> macro), the actual (physical) file name remains the same:</p>
<pre><p>#line __LINE__ "new_file_name.abc"</p></pre>
<h2>Third Form &#8211; #line <em>preprocessor_tokens</em></h2>
<p>The final form of the <code>#line</code> directive allows you to specify  preprocessor tokens to be expanded. After expansion, the third form must look like one of the first two forms. If it does not, the program is malformed. <strong>NOTE:</strong> the preprocessor tokens are expanded, but not evaluated.</p>
<pre><p>#define LINE_NUMBER 100</p>
<p>#define FILE_NAME(f) #f</p>
<p />
<p>#line LINE_NUMBER FILE_NAME(abc.h)</p></pre>
<p>In the above example, <code>LINE_NUMBER</code> is expanded to 100 and <code>FILE_NAME</code> stringizes the passed parameter.</p>
<p>After compilation, the next line will be line number <code>100</code> and the name of the file being compiled will be <code>abc.h</code>.</p>
<div class="c2">
<p><strong>NOTE:</strong> changing the line numbers and file names can cause grief when you try to debug your code.</p>
<p>Changing line numbers and the working file name can make debugging much harder.</p>
<p>When I used GCC to test the code, the debug information contained  line numbering information and file name information that was different from what the IDE (in this case Code::Blocks) knew it to be. When I set breakpoints, Code::Blocks used the line and file name information it was aware of &#8211; which was different from what ended up in the debug information. I had to set the breakpoints manually for the &#8220;correct&#8221; line numbers and file name.</p>
</div>

<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-the-line-directive/">Preprocessor – the #line Directive</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://complete-concrete-concise.com/programming/c/preprocessor-the-line-directive/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Preprocessor – the #pragma Directive</title>
		<link>https://complete-concrete-concise.com/programming/c/preprocessor-the-pragma-directive/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Sun, 17 Jul 2011 19:07:22 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[#pragma]]></category>
		<category><![CDATA[preprocessor]]></category>
		<category><![CDATA[understanding]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=909</guid>

					<description><![CDATA[<p>Behaviour of this preprocessor directive is the same for both C and C++ compilers. Behaviour of this directive is very likely to vary from one compiler vendor to another. Purpose The #pragma directive allows implementation specific control of the compiler. Format #pragma command All preprocessor directives begin with the # symbol. It must be the [&#8230;]</p>
<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-the-pragma-directive/">Preprocessor – the #pragma 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>Behaviour of this preprocessor directive is the same for both C and C++ compilers.<br />
Behaviour of this directive is very likely to vary from one compiler vendor to another.</p>
</div>
<h1>Purpose</h1>
<p>The <code>#pragma</code> directive allows implementation specific control of the compiler.</p>
<h1>Format </h1>
<div class="c2">
<p><strong>#pragma</strong> <em>command</em></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>pragma</code>, but not escape characters or other symbols or macros. The preprocessor removes white space and concatenates the <code>#</code> and <code>pragma</code> together.</p>
<p>If anything follows the <code>#pragma</code> directive (other than white space) then the program is malformed.</p>
<p>The following are valid uses:</p>
<pre>#pragma pack(2)
# pragma once
# /* comments are white space */ pragma long_calls</pre>
<p>The following are invalid uses:</p>
<pre>// #\ is not a valid preprocessor directive
# \t pragma pack(2)
// #" is not a valid preprocessor directive
# "" pragma once</pre>
<h1>Use</h1>
<p>All <code>#pragma</code> commands are compiler specific, so you need to consult your compiler documentation for details.</p>
<p>If the <code>#pragma <em>command</em></code> is not recognized, the preprocessor ignores it.</p>
<p>Pragmas are used to pass information to the compiler that cannot be done through the language.</p>
<p>A common use of pragmas is to specify the packing / alignment of data. Normally, a compiler will align data on the processor&#8217;s natural boundary (which is usually the same as the processor&#8217;s bit size). However, for structures with byte defined data, 8-bit alignment may be required. The following shows byte alignment packing using Microsoft C/C++:</p>
<pre>#pragma pack(push) /* save the current packing value */
#pragma pack(1) /* pack on a 1 byte boundary */
struct some_type_with_8_bit_alignment
{
char a;
short b;
long c;
char d;
};
#pragma pack(pop) /* restore the saved packing value */</pre>

<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-the-pragma-directive/">Preprocessor – the #pragma Directive</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Preprocessor – Understanding the stringizing (#) Operator</title>
		<link>https://complete-concrete-concise.com/programming/c/preprocessor-understanding-the-stringizing-operator/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Sat, 16 Jul 2011 19:47:33 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[#]]></category>
		<category><![CDATA[operator]]></category>
		<category><![CDATA[preprocessor]]></category>
		<category><![CDATA[stringizing]]></category>
		<category><![CDATA[understanding]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=908</guid>

					<description><![CDATA[<p>This is one of three preprocessor operators. The other two operators are the token pasting operator (##) and the define operator. The behaviour is the same for both C and C++ compilers. Purpose The stringizing operator is used to convert parameters passed to a macro into strings. Format # token_to_turn_into_a_string Use The stringizing (#) operator [&#8230;]</p>
<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-understanding-the-stringizing-operator/">Preprocessor – Understanding the stringizing (#) 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 one of three preprocessor operators. The other two operators are the token pasting operator (<code>##</code>) and the <code>define</code> operator.</p>
<p>The behaviour is the same for both C and C++ compilers.</p>
</div>
<h1>Purpose</h1>
<p>The stringizing operator is used to convert parameters passed to a macro into strings.</p>
<h1>Format</h1>
<p><strong>#</strong> <em>token_to_turn_into_a_string</em></p>
<h1>Use</h1>
<p>The stringizing (<code>#</code>) operator may only be used with <code>#define</code> preprocessor directives taking a parameter.</p>
<p>The parameter token immediately to the right of the stringizing operator (ignoring any white space) is transformed by the preprocessor into a string.</p>
<p>For example:</code></p>
<pre>#define make_string(x) #x</pre>
<p>will convert whatever is passed as parameter <code>x</code> into a string.</p>
<p>Leading and trailing white space are deleted.</p>
<p>Any white space between the parameter&#8217;s tokens are collapsed into a single white space character between tokens.</p>
<p>Any conversions necessary to make character literals in the parameter&#8217;s tokens valid in a string are automatically made. This means that characters like: <code>\</code> and <code>"</code> are automatically converted to <code>\\</code> and <code>\"</code> respectively.</p>
<p>If the token is a macro, the macro is not expanded &#8211; the macro name is converted into a string. As a consequence, some characters cannot be stringized – notably, the comma (<code>,</code>) because it is used to delimit parameters and the right parenthesis (<code>)</code>) because it marks the end of the parameter list.</p>
<h2>Examples</h2>
<p>Given the following macros:</p>
<pre><p>#define make_string(x) #x</p>
<p>#define COMMA ,</p></pre>
<p>the following uses:</p>
<pre>make_string(twas brillig);
make_string( twas brillig );
make_string("twas" "brillig");
make_string(twas COMMA brillig);</pre>
<p>get expanded into:</p>
<pre>// no surprise here
"twas brillig"
// leading and trailing spaces were trimmed,
// space between words was compressed to a single space character
"twas brillig"
// the quotes were automatically converted
"\"twas\" \"brillig\""
// the macro COMMA was not expanded
"twas COMMA brillig"</pre>
<div class="c1">
<p>In C99 and the upcoming C++0x languages, you can use a variadic macro to pass commas to the stringizing operator.</p>
<pre>#define make_string(...) # __VA_ARGS__</pre>
<p>Since __VA_ARGS__ does not process the comma separator, you can pass it to the stringizing operator. However, you still cannot pass the right parenthesis.</p>
</div>
<h1>Stringizing a Single Character</h1>
<p>Sometimes you want to create a character literal. Unfortunately, the language does not specify a <em>charizing</em> operator (although, the Microsoft compiler does provide the non-standard operator <code>#@</code> for charizing a single character).</p>
<p>However, you can simulate a <em>charizing</em> operator as follows:</p>
<pre>#define CHARIZE(x) #x[0]</pre>
<p>What this does is stringize whatever is passed as parameter <code>x</code> and then addresses the first character &#8211; effectively acting as though the parameter had been <em>charized</em>. This works in most places a character literal is expected, but not all.</p>

<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-understanding-the-stringizing-operator/">Preprocessor – Understanding the stringizing (#) Operator</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Preprocessor – the #endif Directive</title>
		<link>https://complete-concrete-concise.com/programming/c/preprocessor-the-endif-directive/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Fri, 15 Jul 2011 22:40:58 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[#endif]]></category>
		<category><![CDATA[preprocessor]]></category>
		<category><![CDATA[understanding]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/programming/c/preprocessor-%e2%80%93-the-endif-directive</guid>

					<description><![CDATA[<p>Behaviour of this preprocessor directive is the same for both C and C++ compilers. Purpose The #endif directive is used end / close / terminate a selection block (#if, #ifdef, or #ifndef. Format #if or #ifdef or #ifndef preprocessor or code statements #elif controlling_expression (optional) preprocessor or code statements #else (optional) preprocessor or code statements [&#8230;]</p>
<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-the-endif-directive/">Preprocessor – the #endif 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>Behaviour of this preprocessor directive is the same for both C and C++ compilers.</p>
</div>
<h1>Purpose</h1>
<p>The <code>#endif</code> directive is used end / close / terminate a selection block (<code>#if</code>, <code>#ifdef</code>, or <code>#ifndef</code>.</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> (optional)</p>
<p>preprocessor or code statements</p>
<p> <strong>#else</strong> (optional)</p>
<p>preprocessor or code statements</p>
<p><strong>#endif</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>endif</code>, but not escape characters or other symbols or macros. The preprocessor removes white space and concatenates the <code>#</code> and <code>endif</code> together.</p>
<p>If anything follows the <code>#endif</code> directive (other than white space) then the program is malformed.</p>
<p>The following are valid uses:</p>
<pre>#endif
#   endif
# /* comments are white space */ endif</pre>
<p>The following are invalid uses:</p>
<pre>// #\ is not a valid preprocessor directive
# \t endif
// #" is not a valid preprocessor directive
# "" endif
// malformed because only white space may follow #endif
#endif MY_MACRO</pre>
<h1>Use</h1>
<p>The <code>#endif</code> must appear as the final statement of a preprocessor selection sequence.</p>
<pre><p>#ifdef MY_MACRO</p>
.
.
.
// preprocessor or language statements
.
.
.
<p>#endif</p></pre>

<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-the-endif-directive/">Preprocessor – the #endif Directive</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Preprocessor – the #else Directive</title>
		<link>https://complete-concrete-concise.com/programming/c/preprocessor-the-else-directive/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Wed, 13 Jul 2011 17:39:51 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[#else]]></category>
		<category><![CDATA[preprocessor]]></category>
		<category><![CDATA[understanding]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=898</guid>

					<description><![CDATA[<p>#else 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 #elif. Behaviour of this preprocessor directive is the same for both C and C++ compilers. Purpose The #else directive provides a final alternative for a preprocessor selection block. [&#8230;]</p>
<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-the-else-directive/">Preprocessor – the #else 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><code>#else</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>#elif</code>.</p>
<p>Behaviour of this preprocessor directive is the same for both C and C++ compilers.</p>
</div>
<h1>Purpose</h1>
<p>The <code>#else</code> directive provides a final alternative for a preprocessor selection block. If all previous selection options fail, then the code found between the <code>#else</code> and <code>#endif</code> is compiled.</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> (optional)</p>
<p>preprocessor or code statements</p>
<p> <strong>#else</strong></p>
<p>preprocessor or code statements</p>
<p><strong>#endif</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>else</code>, but not escape characters or other symbols or macros. The preprocessor removes white space and concatenates the <code>#</code> and <code>else</code> together.</p>
<p>If anything follows the <code>#else</code> directive (other than white space) then the program is malformed.</p>
<p>The following are valid uses:</p>
<pre>#else
#   else
# /* comments are white space */ else</pre>
<p>The following are invalid uses:</p>
<pre>// #\ is not a valid preprocessor directive
# \t else
// #" is not a valid preprocessor directive
# "" else
// malformed because only white space may follow #else
#else MY_MACRO</pre>
<h1>Use</h1>
<p>The <code>#else</code> must appear as the last alternative in a preprocessor selection block. If all the preceding selection options fail, then the code contained between the <code>#else</code> and closing <code>#endif</code> is compiled.</p>
<p>The statements following the <code>#else</code> may be language statements or preprocessor statements. There is no limit on the nesting of preprocessor directives or statements.</p>
<pre> #ifdef MY_MACRO
.
.
.
// these statements will only be compiled if MY_MACRO exists
.
.
.
#else
.
.
.
// these statements will only be compiled if MY_MACRO does not exist
.
.
.
#endif</pre>

<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-the-else-directive/">Preprocessor – the #else Directive</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Preprocessor &#8211; the #ifndef Directive</title>
		<link>https://complete-concrete-concise.com/programming/c/preprocessor-the-ifndef-directive/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Wed, 13 Jul 2011 08:36:18 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[#ifndef]]></category>
		<category><![CDATA[preprocessor]]></category>
		<category><![CDATA[understanding]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=888</guid>

					<description><![CDATA[<p>Behaviour of the #ifndef directive is the same in both C and C++. Purpose The #ifndef directive is one of five preprocessor selection statements allowing selection of alternative sections of code for compilation. The other four selection statements are: #ifdef, #if, #elif, and #else. Format #ifndef macro name valid preprocessor or code statements #endif or [&#8230;]</p>
<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-the-ifndef-directive/">Preprocessor &#8211; the #ifndef 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>Behaviour of the <code>#ifndef</code> directive is the same in both C and C++.</p>
</div>
<h1>Purpose</h1>
<p>The <code>#ifndef</code> directive 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>#if</code>, <code>#elif</code>, and <code>#else</code>.</p>
<h1>Format </h1>
<div class="c2">
<p><strong>#ifndef</strong> <em>macro name</em></p>
<p>valid preprocessor or code statements</p>
<p><strong>#endif</strong> or <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>ifndef</code>, but not escape characters or other symbols or macros. The preprocessor removes white space and concatenates the <code>#</code> and <code>ifndef</code> together.</p>
<p>The following are valid uses:</p>
<pre>#ifndef my_macro
# ifndef my_macro;
# ifndef my_macro
# /* comments are white space */ ifndef my_macro</pre>
<p>The following are invalid uses:</p>
<pre>// #\ is not a valid preprocessor directive
# \t ifndef my_macro
// #" is not a valid preprocessor directive
# "" ifndef my_macro</pre>
<h1>Use</h1>
<p>If the macro name does not exist, then the statements following <code>#ifndef</code> until the end of the block (<code>#endif</code>, <code>#else</code> or <code>#elif</code>) are compiled.</p>
<p>If the macro name exists, then the statements following <code>#ifndef</code> until the end of the block (<code>#endif</code>, <code>#else</code> or <code>#elif</code>) are skipped (not compiled).</p>
<p>Since the code is conditionally compiled, it is possible the code never gets compiled and, as a consequence, any errors in it are never caught or noticed.</p>
<p>The simplest preprocessor selection block consists of just an <code>#ifndef</code> and a terminating <code>#endif</code> statement.</p>
<p>More complex selection blocks consist of an <code>#ifndef</code> followed by one or more <code>#elif</code> and / or a final <code>#else</code> statement.</p>
<p>Any valid preprocessor statements, including other <code>#ifndef</code> statements, may be part of the code in the selection block. There is no limit on the level of nesting of selection statements. </p>
<p>The following:</p>
<pre>#ifndef my_macro</pre>
<p>is equivalent to:</p>
<pre>#if !defined my_macro</pre>
<p>This directive is most commonly used to prevent multiple inclusion of header files:</p>
<pre>#ifndef my_header
#define my_header
.
.
.
// contents of the header file
.
.
.
#endif</pre>

<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-the-ifndef-directive/">Preprocessor &#8211; the #ifndef Directive</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<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>
		<item>
		<title>Preprocessor – the #if Directive</title>
		<link>https://complete-concrete-concise.com/programming/c/preprocessor-the-if-directive/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Wed, 13 Jul 2011 10:27:10 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[#if]]></category>
		<category><![CDATA[preprocessor]]></category>
		<category><![CDATA[understanding]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=896</guid>

					<description><![CDATA[<p>This (along with the #elif directive) is probably the second most complicated preprocessor directive because the controlling expression can be complex and include tricky macro replacements. #if is one of five preprocessor selection statements allowing selection of alternative sections of code for compilation. The other four selection statements are: #ifdef, #ifndef, #elif, and #else. Behaviour [&#8230;]</p>
<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-the-if-directive/">Preprocessor – the #if 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>#elif</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>#if</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>#elif</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>#if</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>
<h1>Format </h1>
<div class="c2">
<p><strong>#if</strong> <em>controlling_expression</em></p>
<p>preprocessor or code statements</p>
<p><strong>#elif</strong> or <strong>#else</strong> or <strong>#endif</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>if</code>, but not escape characters or other symbols or macros. The preprocessor removes white space and concatenates the <code>#</code> and <code>if</code> together.</p>
<p>The following are valid uses:</p>
<pre>#if defined my_macro
# if defined my_macro;
# if     defined    my_macro
# /* comments are white space */ if defined my_macro</pre>
<p>The following are invalid uses:</p>
<pre>// #\ is not a valid preprocessor directive
# \t if defined my_macro
// #" is not a valid preprocessor directive
# "" if 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>#if</code> until the end of the block (<code>#endif</code>, <code>#elif</code>, or <code>#else</code>) are compiled. </p>
<pre> #if 3
.
.
.
// because the controlling expression is non-zero (TRUE) everything
// until the end of the current block (#elif 42) will be compiled
.
.
.
#elif 42
.
.
.
// everything in here is skipped because the statements in the first
// block were compiled
.
.
.
#else
.
.
.
// all the statements here are skipped because the statements in the
// first block were compiled
.
.
.
#endif</pre>
<p>If the <em>controlling expression</em> is zero (FALSE), then the statements following the <code>#if</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 defined MY_MACRO</pre>
<p>Identifiers that are not macro names, are replaced with a value of 0 (zero):</p>
<pre>#if SOME_RANDOM_IDENTIFIER</pre>
<p>If the identifier <code>SOME_RANDOM_IDENTIFIER</code> was never defined using <code>#define</code> or was undefined using <code>#undef</code>, then it is assigned the value of 0 (zero). To the preprocessor, it looks like: </p>
<pre>#if 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>The controlling expression may be a simple or complex:</p>
<pre>// a simple controlling expression
#if    3</pre>
<pre>// a more complex controlling expression
#if ( MY_IDENTIFIER > 7 ) && ( VERSION >= 3 )</pre>
<p>Since the code is conditionally compiled, it is possible the code never gets compiled and, as a consequence, any errors in it are never caught or noticed.</p>
<p>Any valid language or preprocessor statements may occur within the selection block – even other <code>#if</code> statements. There is no restriction on the level of nesting permitted.</p>
<p>The following:</p>
<pre>#if defined MY_MACRO</pre>
<p>is equivalent to:</p>
<pre>#ifdef MY_MACRO</pre>
<p>The following:</p>
<pre>#if !defined MY_MACRO</pre>
<p>is equivalent to:</p>
<pre>#ifndef MY_MACRO</pre>
<p>The following:</p>
<pre>#if defined MY_MACRO && defined MY_OTHER_MACRO</pre>
<p>is equivalent to:</p>
<pre>#ifdef MY_MACRO
#  ifdef MY_OTHER_MACRO</pre>

<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-the-if-directive/">Preprocessor – the #if Directive</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Preprocessor – the #ifdef Directive</title>
		<link>https://complete-concrete-concise.com/programming/c/preprocessor-the-ifdef-directive/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Tue, 12 Jul 2011 19:15:00 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[#ifdef]]></category>
		<category><![CDATA[preprocessor]]></category>
		<category><![CDATA[understanding]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/programming/c/preprocessor-%e2%80%93-the-ifdef-directive</guid>

					<description><![CDATA[<p>Behaviour of the #ifdef directive is the same in both C and C++. Purpose The #ifdef directive is one of five preprocessor selection statements allowing selection of alternative sections of code for compilation. The other four selection statements are: #ifndef, #if, #elif, and #else. Format #ifdef macro name valid preprocessor or code statements #endif or [&#8230;]</p>
<p>The post <a href="https://complete-concrete-concise.com/programming/c/preprocessor-the-ifdef-directive/">Preprocessor – the #ifdef 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>Behaviour of the <code>#ifdef</code> directive is the same in both C and C++.</p>
</div>
<h1>Purpose</h1>
<p>The <code>#ifdef</code> directive is one of five preprocessor selection statements allowing selection of alternative sections of code for compilation. The other four selection statements are: <code>#ifndef</code>, <code>#if</code>, <code>#elif</code>, and <code>#else</code>.</p>
<h1>Format </h1>
<div class="c2">
<p><strong>#ifdef</strong> <em>macro name</em></p>
<p>valid preprocessor or code statements</p>
<p><strong>#endif</strong> or <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>ifdef</code>, but not escape characters or other symbols or macros. The preprocessor removes white space and concatenates the <code>#</code> and <code>ifdef</code> together.</p>
<p>The following are valid uses:</p>
<pre>#ifdef my_macro
# ifdef my_macro;
# ifdef my_macro
# /* comments are white space */ ifdef my_macro</pre>
<p>The following are invalid uses:</p>
<pre>// #\ is not a valid preprocessor directive
# \t ifdef my_macro
// #" is not a valid preprocessor directive
# "" ifdef my_macro</pre>
<h1>Use</h1>
<p>If the macro name exists, then the statements following <code>#ifdef</code> until the end of the block (<code>#endif</code>, <code>#else</code> or <code>#elif</code>) are compiled.</p>
<p>If the macro name does not exist, then the statements following <code>#ifdef</code> until the end of the block (<code>#endif</code>, <code>#else</code> or <code>#elif</code>) are skipped (not compiled).</p>
<p>Since the code is conditionally compiled, it is possible the code never gets compiled and, as a consequence, any errors in it are never caught or noticed.</p>
<p>The simplest preprocessor selection block consists of just an <code>#ifdef</code> and a terminating <code>#endif</code> statement.</p>
<p>More complex selection blocks consist of an <code>#ifdef</code> followed by one or more <code>#elif</code> and / or a final <code>#else</code> statement.</p>
<p>Any valid preprocessor statements, including other <code>#ifdef</code> statements, may be part of the code in the selection block. There is no limit on the level of nesting of selection statements. </p>
<p>The following:</p>
<pre>#ifdef my_macro</pre>
<p>is equivalent to:</p>
<pre>#if defined my_macro</pre>
<p>In the following example, <code>#ifdef</code> is used to control whether or not a <code>printf</code> is used to print out the function name whenever the function is called. If DEBUG is defined when the code is compiled, then <code>printf("my_function\n")</code> will be part of the compiled code:</p>
<pre>int my_function(void)
{
#ifdef DEBUG
printf("my_function\n");
#endif
// function body goes here
return some_value;
}</pre>
<p>An alternate way of doing the same thing would be to define a macro:</p>
<pre>#ifdef DEBUG
# define TRACE(x) printf(#x"\n")
#else
# define TRACE(x)
#endif</pre>
<p>and then use the macro in your code:</p>
<pre>int my_function( void )
{
TRACE(my_function);
// function body goes here
return some_value;
}</pre>
<p>When the macro DEBUG is defined, then a <code>printf</code> will be compiled into the code. When the macro DEBUG is not defined, then the macro <code>TRACE</code> is replaced with a blank line.</p>

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