 
    
<?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>stringizing Archives - Complete, Concrete, Concise</title>
	<atom:link href="https://complete-concrete-concise.com/tag/stringizing/feed/" rel="self" type="application/rss+xml" />
	<link>https://complete-concrete-concise.com/tag/stringizing/</link>
	<description>Practical Information Without The Bloat</description>
	<lastBuildDate>Sat, 16 Jul 2011 19:47:33 +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 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>
	</channel>
</rss>
