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