 
    
<?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>Programming Archives - Complete, Concrete, Concise</title>
	<atom:link href="https://complete-concrete-concise.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>https://complete-concrete-concise.com/category/programming/</link>
	<description>Practical Information Without The Bloat</description>
	<lastBuildDate>Wed, 26 Oct 2016 18:11:54 +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>5 Minute Vim Tutorial</title>
		<link>https://complete-concrete-concise.com/blog/5-minute-vim-tutorial/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Wed, 26 Oct 2016 18:11:54 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[Web Tools]]></category>
		<category><![CDATA[Writing]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[understanding]]></category>
		<category><![CDATA[vim]]></category>
		<guid isPermaLink="false">http://www.complete-concrete-concise.com/?p=3186</guid>

					<description><![CDATA[<p>This tutorial won't turn you into a Vim wizard, but at least you will be able to open, navigate, edit, and save files using Vim.</p>
<p>The post <a href="https://complete-concrete-concise.com/blog/5-minute-vim-tutorial/">5 Minute Vim Tutorial</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="preamble">
Vim works differently from other editors you are used to, but it only takes about 5 minutes to learn the basics you need to edit with Vim. You won’t be a Vim wizard, but you will be able to:</p>
<ul>
<li>Open a file</li>
<li>Move around in a file</li>
<li>Edit text in a file</li>
<li>Save a File</li>
</ul>
<p>The slightly longer <a href="#Extended">Extended 5 Minute Tutorial</a> you will show you how to <strong>search</strong> in a file, get <strong>help</strong>, and <strong>access</strong> Vim’s own built-in tutorial.
</div>
<h2 id="contents">Contents</h2>
<ol type="1">
<li><a href="#Vim-in-5">Vim in 5 Minutes (or less)</a></li>
<li><a href="#Extended">The Extended 5+ Minute Tutorial</a>
<ol type="1">
<li><a href="#Normal">Normal Mode</a></li>
<li><a href="#Opening">Opening a File</a></li>
<li><a href="#Saving">Saving a File</a></li>
<li><a href="#Exiting">Exiting Vim</a></li>
<li><a href="#Navigating">Navigating a File</a></li>
<li><a href="#Inserting">Inserting and Deleting Text</a></li>
<li><a href="#Searching">Searching</a></li>
<li><a href="#Help">Getting Help</a></li>
</ol>
</li>
<li><a href="#Final">Final Words</a></li>
</ol>
<h2 id="Vim-in-5">Vim in 5 Minutes (or less)</h2>
<ul>
<li>Vim operates in <span class="mark">Modes</span>. Vim always starts in <span class="mark">Normal Mode</span>.</li>
<li><span class="mark">Normal Mode</span> is your base mode and you should always return to it.</li>
<li>All command / control keys are <strong>case sensitive</strong>.</li>
<li>If you are not in <span class="mark">Normal Mode</span>, you (usually) get back to <span class="mark">Normal Mode</span> by pressing the <span class="kbd">Escape</span> key twice.</li>
<li>If you see <span class="mark">recording</span> in the lower left corner of the screen, press the <span class="kbd">q</span> key to return to <span class="mark">Normal Mode</span>.</li>
<li>If you’ve messed stuff up, return to <span class="mark">Normal Mode</span> and type <span class="kbd">:q!</span> followed by the <span class="kbd">Enter</span> key to exit Vim <strong>without</strong> saving the file.</li>
<li>In <span class="mark">Normal Mode</span> you can navigate the file using the <span class="kbd">h</span>, <span class="kbd">j</span>, <span class="kbd">k</span>, <span class="kbd">l</span> keys (left, down, up, right). You might also be able to use the arrow keys on the keyboard<a id="fnref1" class="footnote-ref" href="#fn1"><sup>1</sup></a>.</li>
<li>When you have navigated to where you want to edit the file (inserting or deleting text), press the <span class="kbd">i</span> key to enter <span class="mark">Insert Mode</span>.</li>
<li>In <span class="mark">Insert Mode</span> you can <strong>only</strong> enter or delete text from the current cursor position &#8211; you <strong>cannot</strong> navigate. To navigate, press the <span class="kbd">Escape</span> key to return to <span class="mark">Normal Mode</span>.</li>
<li>To save (write) the file, return to <span class="mark">Normal Mode</span> and type <span class="kbd">:w</span> followed by the <span class="kbd">Enter</span> key.</li>
<li>To exit (quit) Vim, return to <span class="mark">Normal Mode</span> and type <span class="kbd">:q</span> followed by the <span class="kbd">Enter</span> key.</li>
</ul>
<h2 id="Extended">The Extended 5 Minute Tutorial</h2>
<p>This adds <span class="mark">searching</span> and <span class="mark">help</span> to the 5 Minute Tutorial, but, otherwise, keeps the information to the bare minimum so you can quickly be functional in Vim instead of frustrated.<br />
All command / control keys are <strong>case sensitive</strong>: <span class="kbd">h</span> is not the same as <span class="kbd">H</span>!</p>
<h3 id="Normal">Normal Mode</h3>
<p><span class="mark">Normal Mode</span> is the default mode and it should be the mode you always go back to.<br />
Most times, you press the <span class="kbd">Escape</span> key once or twice<a id="fnref2" class="footnote-ref" href="#fn2"><sup>2</sup></a> to return to <span class="mark">Normal Mode</span>.<br />
If you see <span class="mark">recording</span> in the lower left corner of the screen, press the lowercase <span class="kbd">q</span> key to return to <span class="mark">Normal Mode</span>.</p>
<h3 id="Opening">Opening a File</h3>
<p>The simplest way to open a file is to type <span class="kbd">vim</span> at the command line followed by the name of the file:</p>
<div id="cb1" class="sourceCode">
<pre class="sourceCode bash"><code><a id="cb1-1" class="sourceLine" data-line-number="1"></a><span class="ex">user@COMPUTER</span>:~$ vim file.txt</code></pre>
</div>
<p>If it is a <strong>new</strong> file you should see something like this:</p>
<pre class="vim"><code>
~
~
~
~
~
"file.txt" [New File]                       0,0-1          All</code></pre>
<p>If it is an <strong>existing</strong> file, you should see something like <span class="note" data-note="The actual contents will depend on the file you opened.">this</span>:</p>
<pre class="vim"><code>&lt;!doctype html&gt;
&lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;title&gt;Basic HTML5 Template&lt;/title&gt;
    &lt;link rel="stylesheet" href="style.css"&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;!-- page content goes here --&gt;
    &lt;p&gt;This is some dummy content that is not lorem ipsum.&lt;/p&gt;
  &lt;/body&gt;
&lt;/html&gt;
~
~
~
"basic.html" 12L, 290C                      1,1           All</code></pre>
<p>The status line<a id="fnref3" class="footnote-ref" href="#fn3"><sup>3</sup></a> (at the bottom of the screen) displays the following information:</p>
<ul>
<li>file name</li>
<li>total number of lines in the file</li>
<li>total number of characters in the file</li>
<li>current line the cursor is on</li>
<li>current column the cursor is in</li>
<li>percentage showing the position in the file (if <span class="mark">All</span> : the entire file is visible, <span class="mark">Bot</span> : at the bottom (end) of the file, <span class="mark">Top</span> : at the top of the file)</li>
</ul>
<p>In <span class="mark">Normal Mode</span> load a file by typing <span class="kbd">:edit</span> followed by the filename and then pressing the <span class="kbd">Enter</span> key.:</p>
<pre class="vim"><code>:edit basic.html</code></pre>
<p>This discards the current file (if any) and loads the specified file.<br />
If the file to be discarded has been modified, but not saved, you will see the following warning in the status line:</p>
<pre class="vim"><code>E37: No write since last change (add ! to override)</code></pre>
<p>If you don’t care about saving the file, simply append <span class="kbd">!</span> to the <span class="kbd">:edit</span> command:</p>
<pre class="vim"><code>:edit! basic.html</code></pre>
<p>The <span class="kbd">!</span> tells Vim to “just do it!” and ignore any warnings.</p>
<h3 id="Saving">Saving a File</h3>
<p>You need to be in <span class="mark">Normal Mode</span> to save a file.<br />
Save a file by typing <span class="kbd">:w</span> followed by the <span class="kbd">Enter</span> key.<br />
If you want to save the file with a different name, type <span class="kbd">:w</span> followed by the new file name and then press the <span class="kbd">Enter</span> key:</p>
<pre class="vim"><code>:w new-filename.txt</code></pre>
<h3 id="Exiting">Exiting Vim</h3>
<p>You need to be in <span class="mark">Normal Mode</span> to exit Vim.<br />
Type <span class="kbd">:q</span> followed by the <span class="kbd">Enter</span> key to exit Vim.<br />
If Vim warns you that the file has been modified, you can choose to <a href="#Saving">save it</a> or you can force Vim to exit without saving the file by typing <span class="kbd">:q!</span> followed by the <span class="kbd">Enter</span> key. The <span class="kbd">!</span> tells Vim to “just do it” and exit without saving the file.</p>
<h3 id="navigating-a-file-navigating">Navigating a File {Navigating}</h3>
<p>You need to be in <span class="mark">Normal Mode</span> to navigate a file.<br />
The letters <span class="kbd">h</span>, <span class="kbd">j</span>, <span class="kbd">k</span>, <span class="kbd">l</span> navigate the cursor through the file. (You may also be able to use the arrow keys present on most keyboards.)<br />
They act like arrow keys and are conceptually laid out like this:</p>
<table style="font-size: 2em; text-align: centered; font-family: inconsolata,monospace; border-collapse: collapse;">
<tbody>
<tr>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black;">h<br />
←</td>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black;">j<br />
↓</td>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black;">k<br />
↑</td>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black;">l<br />
→</td>
</tr>
</tbody>
</table>
<p>When you navigate left (<span class="kbd">h</span>) to the beginning of a line, the cursor will stop. It will <strong>not</strong> wrap around and up to the previous line.<br />
When you navigate right (<span class="kbd">l</span>) to the end of a line, the cursor will stop. It will <strong>not</strong> wrap around and down to the next line.<br />
If you type a <strong>positive</strong> integer (which will not be displayed), followed by one of the navigation keys, the cursor will move that many characters / lines.<br />
For example, in <span class="mark">Normal Mode</span>, if you type <span class="kbd">10j</span>, the cursor will move down 10 lines.</p>
<h3 id="Inserting">Inserting and Deleting Text</h3>
<p>In <span class="mark">Insert Mode</span> the only thing you can do is insert or delete text. (You <strong>may</strong> be able to use the arrow keys on your keyboard to navigate the text while in this mode, but there is no guarantee, navigating is supposed to be done in <span class="mark">Normal Mode</span>)<br />
Enter <span class="mark">Insert Mode</span> by pressing the <span class="kbd">i</span>, <span class="kbd">a</span>, <span class="kbd">I</span>, or <span class="kbd">A</span> key.</p>
<ul>
<li><span class="kbd">i</span> insert / delete before the cursor (what you would intuitively expect when entering or deleting text).</li>
<li><span class="kbd">a</span> append / delete after the current cursor position.</li>
<li><span class="kbd">I</span> insert / delete at the beginning of the line.</li>
<li><span class="kbd">A</span> append / delete at the end of the line.</li>
</ul>
<p>You will (probably) be using <span class="kbd">i</span> most frequently.<br />
When you enter <span class="mark">Insert Mode</span> you will see <span class="mark">– INSERT –</span> displayed in the lower left corner:</p>
<pre class="vim"><code>The navigation keys are h, j, k, l.
h moves the̲ cursor one character left
l moves the cursor one character right
j moves the cursor one line down
k moves the cursor one line up
~
~
~
~
-- INSERT --                       3,11      All</code></pre>
<p>Press the <span class="kbd">Escape</span> key to return to <span class="mark">Normal Mode</span>.</p>
<h3 id="Searching">Searching</h3>
<p>You must be in <span class="mark">Normal Mode</span> to search.<br />
In a large file, it is useful to locate items of interest by searching for them.<br />
To search, type <span class="kbd">/</span> followed by the text you want to find, followed by the <span class="kbd">Enter</span> key.<br />
Vim treats the search string as a regular expression &#8211; which means some characters have a special meaning. If you need to search for the following characters, you will need to type them as follows:</p>
<table style="border-collapse: collapse;">
<tbody>
<tr style="font-weight: bold;">
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black;">Name</td>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black;">Character</td>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black;">Need to Type</td>
</tr>
<tr>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black;">Period</td>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black; text-align: center;">.</td>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black; text-align: center;">.</td>
</tr>
<tr>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black;">Asterisk</td>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black; text-align: center;">*</td>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black; text-align: center;">\*</td>
</tr>
<tr>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black;">Backslash</td>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black; text-align: center;">&lt;/td&gt;</td>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black; text-align: center;">\</td>
</tr>
<tr>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black;">Dollar Sign</td>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black; text-align: center;">$</td>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black; text-align: center;">$</td>
</tr>
<tr>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black;">Forward Slash</td>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black; text-align: center;">/</td>
<td style="padding: 0.2em 1em 0 1em; border: 1px solid black; text-align: center;">/</td>
</tr>
</tbody>
</table>
<p>Searches are case sensitive.<br />
You can navigate between search results by pressing <span class="kbd">n</span> (next) or <span class="kbd">N</span> (previous).</p>
<h3 id="Help">Getting Help</h3>
<p>You need to be in <span class="mark">Normal Mode</span> to use help.<br />
To get help on something in Vim, simply type <span class="kbd">:help</span> followed by the thing you want help on.<br />
For example, to get help on the navigation key <span class="kbd">h</span>, type <span class="kbd">:help h</span> followed by the <span class="kbd">Enter</span> key.<br />
You should see something similar to the following:</p>
<pre class="vim"><code>h         or          *h*
&lt;Left&gt;    or          *&lt;Left&gt;*
CTRL-H    or          *CTRL-H* *&lt;BS&gt;*
&lt;BS&gt;      [count] characters to the left.  |exclusive| motion.
          Note: If you prefer &lt;BS&gt; to delete a character, use
          the mapping:
             :map CTRL-V&lt;BS&gt;    X
          (to enter "CTRL-V&lt;BS&gt;" type the CTRL-V key, followed
          by the &lt;BS&gt; key)
          See |:fixdel| if the &lt;BS&gt; key does not do what you
          want.
m̲o̲t̲i̲o̲n̲.̲t̲x̲t̲ ̲[̲H̲e̲l̲p̲]̲[̲R̲O̲]̲ ̲ ̲ ̲ ̲ ̲ ̲ ̲ ̲ ̲ ̲1̲7̲2̲,̲1̲ ̲ ̲ ̲ ̲ ̲ ̲ ̲ ̲ ̲ ̲ ̲1̲2̲%̲ ̲ ̲ ̲ ̲ ̲ ̲ ̲ ̲ ̲ ̲ ̲ ̲
Vim will split the display into two panes. In the upper pane
you will see the help text. In the lower pane you will see your
current editing buffer.
Now you know that Vim supports multiple editing buffers - but
that is not the point of this tutorial.
~
~
~
~
a-file.txt                     4,5              All
</code></pre>
<p>The help can be pretty dense and not user friendly, but it <em>may</em> be helpful.<br />
To close the help window, type <span class="kbd">:q</span> followed by the <span class="kbd">Enter</span> key.<br />
If you type <span class="kbd">:help</span>, it will bring up the general help file. You can navigate through it for topics of interest.<br />
You might also try <span class="kbd">:help tutor</span> for instructions on accessing the Vim tutor which is included with every Vim installation.</p>
<h3 id="Final">Final Words</h3>
<p>Vim may not be the easiest or most intuitive editor you will come across. However, it (or its ancestor Vi) is quite ubiquitous and this tutorial gives you the basics you need so you are minimally functional with it.<br />
The basics are simple:</p>
<ol type="1">
<li>Vim operates in <span class="mark">Modes</span>.</li>
<li>All command / control keys are <strong>case sensitive</strong> : <span class="kbd">k</span> is not the same as <span class="kbd">K</span>.</li>
<li>The base mode is <span class="mark">Normal Mode</span>. You (usually) get back to it by pressing the <span class="kbd">Escape</span> key once or twice.</li>
<li>Navigating a file is done in <span class="mark">Normal Mode</span> using the <span class="kbd">h</span>, <span class="kbd">j</span>, <span class="kbd">k</span>, <span class="kbd">l</span> keys.</li>
<li>When the cursor is where you want to insert or delete text, you press the <span class="kbd">i</span> key to enter <span class="mark">Insert Mode</span>.</li>
<li>Search in <span class="mark">Normal Mode</span> by typing <span class="kbd">/</span> followed by the string you want to find and then the <span class="kbd">Enter</span> key. Navigate the search results using the <span class="kbd">n</span> and <span class="kbd">N</span> keys.</li>
<li>Save a file by typing <span class="kbd">:w</span> in <span class="mark">Normal Mode</span>.</li>
<li>Exit Vim by typing <span class="kbd">:q</span> in <span class="mark">Normal Mode</span>.</li>
<li>In <span class="mark">Normal Mode</span> you can get help by typing <span class="kbd">:help</span></li>
</ol>
<section class="footnotes">
<hr />
<ol>
<li id="fn1">Vi (the precursor to Vim) was developed in 1976. Arrow keys were not commonly found on keyboards, so <span class="kbd">h</span>, <span class="kbd">j</span>, <span class="kbd">k</span>, <span class="kbd">l</span> were used.<a class="footnote-back" href="#fnref1">↩</a></li>
<li id="fn2">Some modes require one key press, others require two. If you press it too many times, the computer will just beep at you. Vim newbies often repeatedly press the <span class="kbd">Escape</span> key in the hopes of returning to <span class="mark">Normal Mode</span><a class="footnote-back" href="#fnref2">↩</a></li>
<li id="fn3">This is true for the default Status Line. It is always possible that someone has modified the Status Line to display different information, or in a different arrangement.<a class="footnote-back" href="#fnref3">↩</a></li>
</ol>
</section>
<p>The post <a href="https://complete-concrete-concise.com/blog/5-minute-vim-tutorial/">5 Minute Vim Tutorial</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Using FLTK with Code::Blocks</title>
		<link>https://complete-concrete-concise.com/programming/fltk/using-fltk-with-codeblocks/</link>
					<comments>https://complete-concrete-concise.com/programming/fltk/using-fltk-with-codeblocks/#comments</comments>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Tue, 12 Nov 2013 20:12:22 +0000</pubDate>
				<category><![CDATA[FLTK]]></category>
		<category><![CDATA[12.10]]></category>
		<category><![CDATA[13.12]]></category>
		<category><![CDATA[codeblocks]]></category>
		<category><![CDATA[directory not found]]></category>
		<category><![CDATA[fltk]]></category>
		<category><![CDATA[project not working]]></category>
		<category><![CDATA[wizard cannot continue]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=3011</guid>

					<description><![CDATA[<p>FLTK is a easy to use, free GUI library. While Code::Blocks provides a FLTK project option, the problem is that it doesn’t work correctly. </p>
<p>The post <a href="https://complete-concrete-concise.com/programming/fltk/using-fltk-with-codeblocks/">Using FLTK with Code::Blocks</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="c1">
<p><a href="http://fltk.org">FLTK</a> is a easy to use, free GUI library.</p>
<p>While Code::Blocks provides a FLTK project option, the problem is that it doesn&#8217;t work correctly. This is because Code::Blocks expects the FLTK <code>include</code> directory to be somewhere else.</p>
<p>These instructions are for FLTK 1.3.2 and Code::Blocks 12.10 or Code::Blocks 13.12 running on Windows 7.</p>
<p>The instructions are probably the same for other version combinations, but no guarantee is made.</p>
<p>Assumes you have already built and installed the FLTK libraries.</p>
</div>
<p>When you try to create a FLTK project using Code::Blocks, after you enter your FLTK directory, you are presented with the following error message:</p>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/11/cb-fix-fltk-project-0.png" alt="The path you entered seems valid, but the wizard can't locate the include directory. The wizard cannot continue." border="0" class="centered"/></p>
<p>This occurs because the Code::Blocks wizard is pretty stupid and expects header files to be found in a <code>/include</code> directory. FLTK, puts its header files in the directory <code>/FL</code>.</p>
<div class="c2">
<p>The function at fault is <code>GetCompilerIncludeDir</code> found in the file <code>common_functions.script</code> located in the <code>..\CodeBlocks\templates\wizard</code> directory.</p>
</div>
<h1>Solution #1</h1>
<div class="c4">
<p><strong>Note:</strong> this does not work for Code::Blocks 13.12</p>
</div>
<div class="c1">
<p>This is the easiest solution, but it changes the FLTK directory structure &#8211; it also means you have file duplication (if you choose the copy option).</p>
</div>
<p><strong>1) Create</strong> an <code>include</code> directory in your FLTK directory:
</p>
<p><strong>2) Copy</strong> (or move) the <code>FL</code> folder into the <code>include</code> directory.</p>
<h1>Solution #2</h1>
<div class="c1">
<p>A little more complicated, but preserves the FLTK directory structure.</p>
</div>
<p>This requires editing the FLTK wizard script.</p>
<p><strong>1) Open</strong> the file <code>wizard.script</code>. This is located in the</p>
<p><code>..\CodeBlocks\share\CodeBlocks\templates\wizard\fltk</code> directory.</p>
<div class="c2">
<p>If you used the standard Code::Blocks install, it is probably located in the <code>C:</code> drive at <code>C:\Program Files (x86)\CodeBlocks\share\CodeBlocks\templates\wizard\fltk</code>.</p>
<p>If the file is located in <code>C:\Program Files (x86)...</code> then you will probably have difficulty editing it because, as a security feature, Windows 7 (and other versions) prevent anyone other than an administrator from editing content in that directory.</p>
<p>You will need to open a file editor with administrator privileges to be able to edit the file.</p>
<p>Instructions on how to open a file editor with administrator privileges can be found <a href="//complete-concrete-concise.com/blog/windows-7-how-to-give-administrator-privilege-to-a-program">here</a>.</div>
<p><strong>2) Locate</strong> <code>FltkPathDefaultInc</code> and <strong>change</strong> <code>#fl.fl</code> to <code>#fl</code> for the line :</p>
<div class="c1">
<p>For Code::Blocks 13.12, you change <code>#fl.include</code> to <code>#fl</code>.</p>
</div>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/11/cb-fix-fltk-project-1.png" alt="" border="0" class="centered"/><br />
<img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/11/cb-fix-fltk-project-2.png" alt="" border="0" class="centered"/></p>
<p><strong>3) Comment out</strong> (or delete) the entire function <code>OnLeave_FltkPath(fwd)</code> (you can use the standard C++ single line comment <code>//</code> to comment out each line):</p>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/11/cb-fix-fltk-project-3.png" alt="" border="0" class="centered"/></p>
<p><strong>4) Restart</strong> Code::Blocks (if Code::Blocks was open when you made these changes).</p>

<p>The post <a href="https://complete-concrete-concise.com/programming/fltk/using-fltk-with-codeblocks/">Using FLTK with Code::Blocks</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/fltk/using-fltk-with-codeblocks/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>warning: [options] bootstrap class path not set in conjunction with -source 1.5</title>
		<link>https://complete-concrete-concise.com/programming/java/warning-options-bootstrap-class-path-not-set-in-conjunction-with-source-1-5/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Wed, 03 Apr 2013 16:38:58 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[-source]]></category>
		<category><![CDATA[bootstrap class]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[NetBeans]]></category>
		<category><![CDATA[warning]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=2758</guid>

					<description><![CDATA[<p>When compiling with Java, you may get a warning message similar (or identical to): warning: [options] bootstrap class path not set in conjunction with -source 1.5 This warning is emitted if you are using JDK 7 Build 121 or later (earlier versions of the compiler would not issue a warning). It is warning you that [&#8230;]</p>
<p>The post <a href="https://complete-concrete-concise.com/programming/java/warning-options-bootstrap-class-path-not-set-in-conjunction-with-source-1-5/">warning: [options] bootstrap class path not set in conjunction with -source 1.5</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>When compiling with Java, you may get a warning message similar (or identical to):</p>
<pre><code>warning: [options] bootstrap class path not set in conjunction with -source 1.5</code></pre>
<p>This warning is emitted if you are using JDK 7 Build 121 or later (earlier versions of the compiler would not issue a warning).</p>
<p>It is warning you that your Java compiler version and the version of Java you are compiling for are different. For example, you may have version 7 of the compiler installed, but are choosing to compile for Java version 5.0. While the compiler is capable of emitting code for different versions, it needs to use the correct startup libraries (bootstrap) in order to guarantee it will function correctly.</p>
<div class="c1">
<p>In any other language, this would be called &#8220;linking against the correct startup libraries&#8221;, but in Java, it is called &#8220;compiling against bootstrap and extension classes&#8221;.</p>
</div>
<h1>For Users of NetBeans IDE</h1>
<div class="c1">
<p>These instructions are for NetBeans IDE 7.3.</p>
<p>I suspect the instructions are the same for other versions of NetBeans IDE, but I make no guarantee.</p>
</div>
<p>You can correct the warning by ensuring the compiler version and binary version are the same:</p>
<p><strong>1) Right-click</strong> on the project:</p>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/warning-bootstrap-class-path-not-set-1.png" alt="" border="0" class="centered"/></p>
<p><strong>2) Select</strong> <u>Properties</u>:</p>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/warning-bootstrap-class-path-not-set-2.png" alt="" border="0" class="centered"/></p>
<p><strong>3) Ensure</strong> that the <u>Source/Binary Format:</u> under the <u>Sources</u> category, matches the <u>Java Platform</u> under the <u>Libraries</u> category (click for full sized image):</p>
<p><a href="//complete-concrete-concise.com/wp-content/uploads/2013/04/warning-bootstrap-class-path-not-set-3-big.png" target="_blank"><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/warning-bootstrap-class-path-not-set-3-thumb.png" alt="" border="0" class="centered"/></a></p>
<h1>For Command Line Users</h1>
<p>If you are compiling using the command line, then you need to ensure that the <code>-source</code> and <code>-target</code> options refer to the same version and the <code>-bootclasspath</code> option refers to the correct Java runtime.</p>
<p>For example, if you have JDK 7 installed and want to compile for Java 5.0, then the command line would be:</p>
<pre><code>javac -source 1.5 -target 1.5 -bootclasspath <u><em>path-to-java-5.0-runtime</em></u> <em>code.java</em></code></pre>
<p>Where <code>path-to-java-5.0-runtime</code> is the path to the <code>rt.jar</code> file of Java 5.0 (note: you have to include <code>rt.jar</code> as part of the path.</p>
<p>Where <code>code.java</code> is Java code compatible with version 5.0.</p>
<div class="c1">
<p>Note: The mapping from Java version to command line attributes are:</p>
<ul>
<li>Java 1.2 => 1.3 (unless there is a typo in the JDK 7 warning, it is 1.3 not 1.2)</li>
<li>Java 1.3 => 1.3</li>
<li>Java 1.4 => 1.4</li>
<li>Java 5.0 => 1.5</li>
<li>Java 6 => 1.6</li>
</ul>
</div>
<p>Normally, you do not have to specify the <code>-target</code> option because by default it is set the same as the <code>-source</code> option.</p>
<h1>For Other IDE Users</h1>
<p>You will have to read (or explore) your IDE to determine where the compiler and target settings are located. It is probably a safe bet that they are part of the project options (try right-clicking on the project name and see if a menu pops up, or see if there is something like a <u>Project Options</u> setting somewhere.</p>
<h1>More Information</h1>
<div class="c1">
<p>These are external links and where deemed to be safe and relevant at the time of publication.</p>
<p>If there are problems with them, please let me know.</p>
</div>
<p><a href="http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/javac.html">javac &#8211; Java programming language compiler</a> &#8211; search for <code>bootclasspath</code> on the page</p>
<p><a href="http://www.oracle.com/technetwork/java/javase/compatibility-417013.html">Java SE 7 and JDK 7 Compatibility</a> &#8211; a discussion about Java 7 compatibility with previous versions</p>

<p>The post <a href="https://complete-concrete-concise.com/programming/java/warning-options-bootstrap-class-path-not-set-in-conjunction-with-source-1-5/">warning: [options] bootstrap class path not set in conjunction with -source 1.5</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Programming Error &#8211; Unintended String Concatenation</title>
		<link>https://complete-concrete-concise.com/programming/c/programming-error-unintended-string-concatenation/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Tue, 19 Mar 2013 08:38:42 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[comma]]></category>
		<category><![CDATA[concatenation]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[missing]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[programming]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=2699</guid>

					<description><![CDATA[<p>In an effort to be helpful, C and C++ compilers concatenate adjacent strings together. In the following example, the compiler will concatenate the two strings into a single string: printf("This is a string " "and this is another string."); Which is probably what you intended anyway. Because C and C++ are free form languages, adjacent [&#8230;]</p>
<p>The post <a href="https://complete-concrete-concise.com/programming/c/programming-error-unintended-string-concatenation/">Programming Error &#8211; Unintended String Concatenation</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In an effort to be helpful, C and C++ compilers concatenate adjacent strings together.</p>
<p>In the following example, the compiler will concatenate the two strings into a single string:</p>
<pre><code>printf("This is a string " "and this is another string.");</code></pre>
<p>Which is probably what you intended anyway.</p>
<p>Because C and C++ are free form languages, adjacent strings can appear in many different formats &#8211; as this string table shows:</p>
<pre><code>char *array[] = {
    "str_1",
    "str_2",
    "str_3"
    "str_4",
    "str_5",
    NULL};</code></pre>
<p>Did you notice the missing comma (,) after <code>"str_3"</code>? It can be a hard one to spot.</p>
<p>This is the type of bug that can result in something like a simple parser failing:</p>
<pre><code>if (strcmp(array[i], test_string) == 0)</code></pre>
<p>because <code>str_3</code> and <code>str_4</code> will never be matched, but the others will.</p>

<p>The post <a href="https://complete-concrete-concise.com/programming/c/programming-error-unintended-string-concatenation/">Programming Error &#8211; Unintended String Concatenation</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Keyword &#8211; switch, case, default</title>
		<link>https://complete-concrete-concise.com/programming/c/keyword-switch-case-default/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Thu, 22 Mar 2012 06:56:52 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[break]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[case]]></category>
		<category><![CDATA[default]]></category>
		<category><![CDATA[keyword]]></category>
		<category><![CDATA[switch]]></category>
		<category><![CDATA[understanding]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=1594</guid>

					<description><![CDATA[<p>The switch keyword is probably the least well understood of the C/C++ language keywords (although, const probably comes a close second). The keywords switch, case, and default always go together and cannot be used independently in any other context. There is a small difference in behaviour between C and C++. Most programmers will never notice [&#8230;]</p>
<p>The post <a href="https://complete-concrete-concise.com/programming/c/keyword-switch-case-default/">Keyword &#8211; switch, case, default</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="c1">
<p>The <code>switch</code> keyword is probably the least well understood of the C/C++ language keywords (although, <code>const</code> probably comes a close second).</p>
<p>The keywords <code>switch</code>, <code>case</code>, and <code>default</code> always go together and cannot be used independently in any other context.</p>
<p>There is a small difference in behaviour between C and C++. Most programmers will never notice the difference.</p>
</div>
<p>The most common use of <code>switch</code> is as a replacement for multiple <code>if-else</code> statements:</p>
<pre><code>
                               switch (value)
                               {
if (value == 1)                   case 1:
{                                      ...
  ...                                 break;
} else if (value == 2)            case 2:
{                                      ...
  ...                                 break;
} else                            default:
{                                      ...
  ...                                 break;
}                              }</code></pre>
<p>This usage is quite well understood. Its use as a jump table into a block of code is less well understood (and, to be honest, rarely used).</p>
<h1>Format</h1>
<pre><code><strong>switch</strong> ( <em>controlling expression</em> )
{
   <strong>case</strong>: <em>constant expression</em>  // optional
         .        .
         <em>code statements</em>
         .        .
         break;  // optional
   <strong>default</strong>:  //optional
         .        .
         <em>code statements</em>
         .        .
         break;  // optional
}</code></pre>
<h3>switch (<em>controlling expression</em>)</h3>
<p>Every <code>switch</code> block must begin with the <code>switch</code> keyword. If you want a <code>switch</code> block then you have to use the <code>switch</code> keyword.</p>
<p>C and C++ differ in the way the <em>controlling expression</em> is handled. </p>
<p><u><strong>In C</strong></u> the expression is converted to type <code>int</code> using C conversion rules. This means the <em>controlling expression</em> can be anything C knows how to convert to an <code>int</code>: the signed and unsigned varieties of <code>char</code>, <code>short</code>, <code>int</code>, <code>long </code> and <code>long long</code> as well as <code>float</code>, <code>double</code>, and <code>long double</code>.</p>
<p><u><strong>In C++</strong></u> the <em>controlling expression</em> must be an <u>integral</u> type &#8211; any of the signed or unsigned varieties of <code>char</code>, <code>short</code>, <code>int</code>, <code>long</code>, or <code>long long</code> &#8211; or any <code>class</code>, <code>struct</code>, or <code>union</code> for which there exists an unambiguous conversion to an integral type. Using a <code>float</code>, <code>double</code>, or <code>long double</code> is an error (unless, of course, you explicitly cast it to one of the integral types).</p>
<div class="c1">
<p>An &#8220;implicit&#8221; conversion from a <code>class</code>, <code>struct </code>or <code>union </code>to an integral type might seem new to some. Here is an example:</p>
<pre><code>class A
{
 private:
    int value;
 public:
    operator int() {return value;} // conversion method
};</code></pre>
<p>This can be used in a <code>switch</code> statement as follows:</p>
<pre><code>
int main(void)
{
   A a;  // variable of type A above with conversion to int
   switch (a) // works because compiler calls operator int()
   {
      .
      .
      .
   }
   return 0;
}</code></pre>
<p>In the above example, when an object of type A is used anywhere a type <code>int</code> is expected, the conversion operator <code>int()</code> will be called.</p>
<p>If we expand the class by adding another conversion operator to a different integral type, say</p>
<pre><code>operator char() {return char(value);}</code></pre>
<p>then it is no longer unambiguous because there are two integral types to choose from: <code>int</code> or <code>char</code>. The compile will fail because the compiler cannot resolve between the two integral types.</p>
<p>Conversions can be ambiguous in other types of code as well:</p>
<pre><code>A a;
int i;
char c;
short s;
i = a; // compiler calls operator int()
c = a; // compiler calls operator char();
s = a; // compiler cannot resolve between int() and char()</code></pre>
</div>
<h3>case (<em>constant expression</em>)</h3>
<div class="c1">
<p><code>case</code> statements are optional &#8211; you don&#8217;t have to have any. But, you do need at least one <code>case</code> or <code>default</code> statement in your <code>switch</code> body.</p>
</div>
<p>The <em>constant expression</em> is called a <u>label</u> or <u>case label</u>.</p>
<p>Unlike the <em>controlling expression</em>, the <code>case</code> label must be known at compile time &#8211; it cannot be a variable or in any other way determined at run time.</p>
<p>All <code>case</code> labels must be different. If two <code>case</code> labels resolve to the same value, then the program is malformed and the compile will fail.</p>
<div class="c1">
<p>The two most common ways that <code>case</code> labels get the same value is through macros or enums:</p>
<pre><code>
// at one time, the following macros all had different values
// but at some point the difference between CONDITION_1 and
// CONDITION_2 was lost and they became the same.
// Most code will work just fine with this change, but not a
// switch block if it is using these labels.
#define CONDITION_1 0
#define CONDITION_2 0  // duplicated value
#define CONDITION_3 2
// instead of using macros, the conditions were encapsulated
// in an enum, but at some point the difference between CONDITION_1
// and CONDITION_2 was lost and they became the same.
// Most code will work just fine with this change, but not a
// switch block if it is using these labels.
enum Some_Values
{
   CONDITION_1 = 0,
   CONDITION_2 = 0, // duplicated value
   CONDITION_3 = 1
};
// when either the macros or enum values are used for the case
// labels, the program becomes malformed because two labels
// have the same value
switch (value)
{
   case CONDITION_1:
   case CONDITION_2: // compile will fail
   case CONDITION_3:
   default:
}</code></pre>
</div>
<p>C and C++ differ in the way they handle the <em>constant expression</em>.</p>
<p><u><strong>In C</strong></u>, the the expression is converted to type <code>int</code>. Both the <em>controlling expression</em> and <em>constant expression</em> are of type <code>int</code>.</p>
<p><u><strong>In C++</strong></u>, the expression is converted to the type of the <em>controlling expression</em>. This means the <em>constant expression</em> is the same type as the <em>controlling expression</em>.</p>
<h3>default</h3>
<div class="c1">
<p>The <code>default</code> statement is optional &#8211; you don&#8217;t have to have one. But, you do need at least one <code>case</code> or <code>default</code> statement in your <code>switch</code> body.</p>
</div>
<p>The <code>default</code> statement is where the <code>switch</code> operator jumps to if none of the <code>case</code> labels match the <em>controlling expression</em>.</p>
<h1>Using switch for Multiway Selection</h1>
<div class="c1">
<p>This is the most common (and best understood) use of the <code>switch</code> statement.</div>
<p>The <code>switch</code> statement is most commonly used when you want to choose one of several code paths and the decision is based on some sort of integer value (an <code>enum</code> is an integer at heart).</p>
<p>For simple choices, an <code>if-else</code> block works fine. But when you have many possible code paths to choose from, having a long chain of <code>if-else</code> statements can be unwieldy.</p>
<p>Consider a basic DVD player that responds to the following commands:</p>
<pre><code>enum PLAYER_COMMANDS
{
   Off,
   On,
   Stop,
   Play,
   Pause,
   Eject
};</code></pre>
<p>Implemented using <code>if-else</code> statements, the code would look like this:</p>
<pre><code>if (command == Off)
{
   ... code ...
}
else if (command == On)
{
   ... code ...
}
... remaining else-if code ...
else
{
   printf("Error - unknown state\n");
}</code></pre>
<p>Using a <code>switch</code> statement, the code would look like this:</p>
<pre><code>switch (command)
{
   case Off:
      ... code ...;
      break;
   case On:
      ... code ...;
      break;
   ... remaining cases ...
   default:
      printf("Error - unknown state\n");
}</code></pre>
<p>The <code>switch</code> block looks neater and more compact than the nested <code>if-else</code> code.</p>
<h3>Order of case statements</h3>
<p>The <code>case</code> and <code>default</code> statements inside the <code>switch</code> don&#8217;t have to be in any particular order. While not typical, it is perfectly valid to have the <code>default</code> statement at the top of the block (or in the middle of the block):</p>
<pre><code>switch (controlling_expression)
{
   default: <em>// not typical location, but perfectly legal</em>
      ... some code ...
      break;
   case label_1:
      ... some code ...
     break;
};</code></pre>
<h3>Use of break</h3>
<p>Usually, a <code>break</code> statement is placed at just before the next <code>case</code> (or <code>default</code>) statement.</p>
<p>Code execution stops at the <code>break</code> statement and continues at the next statement following the <code>switch</code> block.</p>
<p>If there is no <code>break</code> statement, then the code continues to be executed until either (1) a <code>break</code> statement is encountered, or (2) execution exits the <code>switch</code> block.</p>
<pre><code>switch (controlling_expression)
{
   case label_1:
      ... some code 1 ...
   case label_2:
      ... some code 2 ...
      break;
   default:
      ... some code 3 ...
};</code></pre>
<p>In the above example, if the <em>controlling_expression</em> switches to:</p>
<ul>
<li><u>label_1</u>: then <em>some code 1</em> will be executed. Since there is no <code>break</code> statement, execution will fall through and execute <em>some code 2</em>. Since there is a <code>break</code> after <em>some code 2</em> code execution will continue at the next statement following the <code>switch</code> block.</li>
<li><u>label_2</u>: then <em>some code 2</em> will be executed. Since there is a <code>break</code> statement, code execution will continue at the next statement following the <code>switch</code> block.</li>
<li><u>default</u>: then <em>some code 3</em> will be executed. There is no <code>break</code> statement (it is optional for the last final label) because the next statement to be executed will be the one following the <code>switch</code> block.</li>
</ul>
<h3>Using Fall-through</h3>
<p>Fall-through can be useful.</p>
<p>Unlike some other languages, C and C++ don&#8217;t allow a range of values for for a <code>case</code> label. For example, you could not write:</p>
<pre><code>switch (month)
{
   case January ... July :
      ... some code ...
};</code></pre>
<p>But, using fall-through, you can write code like this:</p>
<pre><code>switch (month)
{
   case January:
   case March:
   case May:
   case July:
   case August:
   case October:
   case December:
      days = 31;
      break;
   case April:
   case June:
   case September:
   case November:
     days = 30;
     break;
   case February:
     days = 28;
};</code></pre>
<p>In the above example, January falls through to the assignment <code>days = 31;</code></p>
<h1>Using switch as a Jump Table</h1>
<div class="c1">
<p>This is the least commonly understood and used behaviour of the <code>switch</code> statement. Its most infamous example is <u>Duff&#8217;s Device</u>.</p>
</div>
<p>A common complaint of programmers coming from other languages is that the <code>switch</code> in C and C++ is broken &#8211; it seems dumb to have to explicitly code a <code>break</code> to prevent fall-through in <code>case</code> statements. That&#8217;s because in most languages a <code>switch</code> or <code>case</code> block is compact way of selecting a block of code to execute. This is not the case in C and C++. In C and C++, the <code>switch</code> statement is not for selecting a block of code to execute, it is a <u>jump table</u> <u>into</u> a block of code.</p>
<p>Consider the following:</p>
<pre><code>switch (control)
{
   default:
      printf ("Hello world!!!\n");
      printf ("Hello world!!!\n");
      printf ("Hello world!!!\n");
      printf ("Hello world!!!\n");
      printf ("Hello world!!!\n");
      printf ("Hello world!!!\n");
      printf ("Hello world!!!\n");
      printf ("Hello world!!!\n");
}</code></pre>
<p>No matter what value <code>control</code> has, the 8 <code>printf</code> statements will be executed. We might as well not even have the <code>switch</code> statement to begin with. The code is, effectively, identical to 8 <code>printf</code> statements enclosed in their own block:</p>
<pre><code>{
   printf ("Hello world!!!\n");
   printf ("Hello world!!!\n");
   printf ("Hello world!!!\n");
   printf ("Hello world!!!\n");
   printf ("Hello world!!!\n");
   printf ("Hello world!!!\n");
   printf ("Hello world!!!\n");
   printf ("Hello world!!!\n");
}</code></pre>
<p>We could also write it this way:</p>
<pre><code>goto DEFAULT: // whatever the value of control
{
DEFAULT:
      printf ("Hello world!!!\n");
      printf ("Hello world!!!\n");
      printf ("Hello world!!!\n");
      printf ("Hello world!!!\n");
      printf ("Hello world!!!\n");
      printf ("Hello world!!!\n");
      printf ("Hello world!!!\n");
      printf ("Hello world!!!\n");
}</code></pre>
<p>Consider the following (which will print Hello World!!! either 1, 2, 3, 4, 5, or 8 times depending on the value of <code>control</code>):</p>
<pre><code>switch (control)
{
   default:
      printf ("Hello world!!!\n");
      printf ("Hello world!!!\n");
      printf ("Hello world!!!\n");
   case 5:
      printf ("Hello world!!!\n");
   case 4:
      printf ("Hello world!!!\n");
   case 3:
      printf ("Hello world!!!\n");
   case 2:
      printf ("Hello world!!!\n");
   case 1:
      printf ("Hello world!!!\n");
}</code></pre>
<p>It can be rewritten as:</p>
<pre><code>if (control == 1) goto LABEL_1;
if (control == 2) goto LABEL_2;
if (control == 3) goto LABEL_3;
if (control == 4) goto LABEL_4;
if (control == 5) goto LABEL_5;
else goto DEFAULT;
{
DEFAULT:
      printf ("Hello world!!!\n");
      printf ("Hello world!!!\n");
      printf ("Hello world!!!\n");
LABEL_5:
      printf ("Hello world!!!\n");
LABEL_4:
      printf ("Hello world!!!\n");
LABEL_3:
      printf ("Hello world!!!\n");
LABEL_2:
      printf ("Hello world!!!\n");
LABEL_1:
      printf ("Hello world!!!\n");
}</code></pre>
<p>It should be obvious that a <code>switch</code> block is a constrained <code>goto</code> where you can jump to any line inside the block via an appropriate <code>case</code> label.</p>
<div class="c1">
<p>There is no need to get alarmed, <u>every</u> control statement in <u>every</u> programming language that alters the flow of program execution is a constrained goto.</p>
<p>Consider a <code>do-while</code> loop:</p>
<pre><code>do
{
   x = x + 2;
}
while (x &lt; 100);</code></pre>
<p>This is identical to:</p>
<pre><code>DO:
{
   x = x + 2;
}
if (x &lt; 100) goto DO;</code></pre>
</div>
<p>Knowing this helps to understand some of the &#8220;weird&#8221; behaviour of the <code>switch</code> statement in C and C++.</p>
<h3>Fall-through</h3>
<p>Fall through occurs because we <u>do not select</u> a block of code to execute, but <u>jump to a line of code</u> (within the block) and continue execution from there.</p>
<p>The <code>break</code> at the end of what we want to execute is simply a <code>goto</code> to the end of the block.</p>
<div class="c1">
<p>Looked at another way, <code>switch</code> or <code>case</code> constructs in other languages do exactly the same thing, except that before the next label, they implicitly insert a <code>goto</code> to the end of the block.</p>
<p>Consider the following example in Pascal:</p>
<pre><code> case A of
   0: writeln('nothing');
   1: writeln('number 1');
   2: writeln('number 2');
   else writeln('big number');
 end;</code></pre>
<p>This is identical to:</p>
<pre><code>if A = 0 then goto ZERO;
if A = 1 then goto ONE;
if A = 2 then goto TWO else goto BIG;
ZERO:
   writeln('nothing');
   goto CONTINUE;
ONE:
   1: writeln('number 1');
   goto CONTINUE;
TWO:
   2: writeln('number 2');
   goto CONTINUE;
BIG:
   writeln('big number');
CONTINUE:</code></pre>
<p>Notice the implicit <code>goto</code>s inserted to prevent fall-through.
</div>
<h3>Initialization Errors</h3>
<p>It is common to want to use some local variables in a <code>case</code> label. Unfortunately, doing so can generate a compile time error that the variable has not been initialized:</p>
<pre><code>switch (value)
{
   int a = 7;
   case 1:
       printf("%d\n", a);
       break;
   default:
       printf("%d\n", a * a);
}</code></pre>
<p>In this example, when the code jumps to <code>case 1</code> or <code>default</code> it bypasses the initialization of <code>a</code>.</p>
<h3>Jumping into the middle of and embedded switch</h3>
<p>Since a <code>switch</code> statement allows you to jump to an arbitrary point in a block of code, it is reasonable to ask if it is possible to jump into the middle of a nested <code>switch</code> block:</p>
<pre><code>switch (value)
{
   case LABEL_1:
      switch (value_2)
      {
         case OTHER_LABEL_1:
            ... code ...
            break;
         case LABEL_2:  // can <strong>switch (value)</strong> jump here?
            ... code ...
            break;
      }
   case LABEL_3:
      ... code ...
      break;
}</code></pre>
<p>The answer is <strong>no</strong>. This is because scope and visibility rules don&#8217;t allow <code>value</code> of the first <code>switch</code> to be seen inside of the nested <code>switch</code> block.</p>
<p>The following should make this clear:</p>
<pre><code>int A = 7; // this is the outer_A
{   // start a new block
   int A = 3; // this is the inner_A
  // inside this block, the value of the outer_A is not visible
  // (ok, in C++ you could use the :: scope resolution operator
  //  to see the outer_A, but that is not the point)
}</code></pre>
<p>In a similar way, the value of the <em>controlling expression</em> in the outer <code>switch</code> is hidden by the value of the <em>controlling expression</em> of the nested <code>switch</code>. This means the outer <em>controlling expression</em> has no scope within the nested <code>switch</code>, so it cannot jump into the middle of a nested <code>switch</code>.</p>

<p>The post <a href="https://complete-concrete-concise.com/programming/c/keyword-switch-case-default/">Keyword &#8211; switch, case, default</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<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>
	</channel>
</rss>
