<?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/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>The Global Engineer's Notebook</title>
	<atom:link href="http://globalengineer.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://globalengineer.wordpress.com</link>
	<description>Notes on computer engineering</description>
	<lastBuildDate>Sat, 07 Nov 2009 02:59:23 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='globalengineer.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/c75f410ba252ef7942bf17b9941ed471?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>The Global Engineer's Notebook</title>
		<link>http://globalengineer.wordpress.com</link>
	</image>
			<item>
		<title>Vi: finding a matching brace</title>
		<link>http://globalengineer.wordpress.com/2009/11/07/vi-finding-a-matching-brace/</link>
		<comments>http://globalengineer.wordpress.com/2009/11/07/vi-finding-a-matching-brace/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 02:59:23 +0000</pubDate>
		<dc:creator>globalengineer</dc:creator>
				<category><![CDATA[Vi/Vim]]></category>

		<guid isPermaLink="false">http://globalengineer.wordpress.com/?p=244</guid>
		<description><![CDATA[If you write software in a language that uses braces or parenthesis like C++ or Java, you might find yourself trying to find an opposing brace somewhere in your code.  With Vim, the job is quite easy.  You simply put your cursor on a brace or parenthesis, press %, and Vi will move the cursor [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=244&subd=globalengineer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>If you write software in a language that uses braces or parenthesis like C++ or Java, you might find yourself trying to find an opposing brace somewhere in your code.  With Vim, the job is quite easy.  You simply put your cursor on a brace or parenthesis, press %, and Vi will move the cursor to the corresponding brace or parenthesis.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/globalengineer.wordpress.com/244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/globalengineer.wordpress.com/244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/globalengineer.wordpress.com/244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/globalengineer.wordpress.com/244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/globalengineer.wordpress.com/244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/globalengineer.wordpress.com/244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/globalengineer.wordpress.com/244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/globalengineer.wordpress.com/244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/globalengineer.wordpress.com/244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/globalengineer.wordpress.com/244/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=244&subd=globalengineer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://globalengineer.wordpress.com/2009/11/07/vi-finding-a-matching-brace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6370396c5129eb47b3bccec6515adaaa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">globalengineer</media:title>
		</media:content>
	</item>
		<item>
		<title>Vim: comment blocks</title>
		<link>http://globalengineer.wordpress.com/2009/10/30/vim-comment-blocks/</link>
		<comments>http://globalengineer.wordpress.com/2009/10/30/vim-comment-blocks/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 12:14:31 +0000</pubDate>
		<dc:creator>globalengineer</dc:creator>
				<category><![CDATA[Vi/Vim]]></category>

		<guid isPermaLink="false">http://globalengineer.wordpress.com/?p=237</guid>
		<description><![CDATA[I have become tired of using the arrow keys to navigate around my source code just to insert comments on each line of a block of code.  Wouldn&#8217;t it be nice if I could just select a few lines, hit a button or two, and have all of the lines commented out or un-commented?  (Like [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=237&subd=globalengineer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have become tired of using the arrow keys to navigate around my source code just to insert comments on each line of a block of code.  Wouldn&#8217;t it be nice if I could just select a few lines, hit a button or two, and have all of the lines commented out or un-commented?  (Like in Max-PlusII or QuartusII support in their VHDL editors&#8230;)</p>
<p>Well Vim has the ability to do so!  First of all, let me introduce the visual-block command.  In Vim, pressing <strong>v</strong> allows you to select text. Visual-block is enabled by pressing <strong>Cntl-v</strong>.  Notice the difference in the following two screen shots.</p>
<div id="attachment_238" class="wp-caption aligncenter" style="width: 490px"><img class="size-full wp-image-238" title="visual" src="http://globalengineer.files.wordpress.com/2009/10/visual.jpg?w=480&#038;h=339" alt="visual" width="480" height="339" /><p class="wp-caption-text">Regular Visual Mode in Vim</p></div>
<div id="attachment_239" class="wp-caption aligncenter" style="width: 490px"><img class="size-full wp-image-239" title="block" src="http://globalengineer.files.wordpress.com/2009/10/block.jpg?w=480&#038;h=339" alt="block" width="480" height="339" /><p class="wp-caption-text">Visual-block mode in Vim</p></div>
<p>In visual mode, if you move downward, the entire line is selected, but in visual-block mode, only the text in the same column is selected.  In visual-block mode, if you move to the right, more columns are selected.</p>
<p>To insert comments, select the text rows that you want to block comment-out with visual-block, <strong>Cntl-v</strong>. Now press <strong>I</strong>, and then the commenting characters that you want to insert.  For C++ you would want <strong>//</strong>, for Ada or VHDL <strong>&#8211;</strong>, or for scripting languages a <strong>#</strong> would do the trick. Finally, press the <strong>Esc</strong> key to end the visual-block command.  The block of code should now be commented out!</p>
<p>To remove comments from a block of test, usual the visual-block command (<strong>Cntl-v</strong>) and select the columns of comment text, and then press <strong>d</strong>, and that should take care of it.</p>
<p>Removing comments is easy enough, but wouldn&#8217;t it be nice to have an easier way to add comment blocks without all of those keys to press?  Well, why don&#8217;t we map the keystrokes to a single key?  Edit your <strong>.vimrc</strong> and add the following as needed:</p>
<blockquote><p>
map &lt;F2&gt; I&#8211;&lt;Esc&gt;&lt;Esc&gt;<br />
map &lt;F3&gt; I//&lt;Esc&gt;&lt;Esc&gt;<br />
map &lt;F4&gt; I#&lt;Esc&gt;&lt;Esc&gt;
</p></blockquote>
<p>Now I can simply select the text block with visual-block, and press a function key to insert comments for Ada, C++ or shell scripts.  I&#8217;m just beginning to see the real power of Vim.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/globalengineer.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/globalengineer.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/globalengineer.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/globalengineer.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/globalengineer.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/globalengineer.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/globalengineer.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/globalengineer.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/globalengineer.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/globalengineer.wordpress.com/237/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=237&subd=globalengineer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://globalengineer.wordpress.com/2009/10/30/vim-comment-blocks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6370396c5129eb47b3bccec6515adaaa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">globalengineer</media:title>
		</media:content>

		<media:content url="http://globalengineer.files.wordpress.com/2009/10/visual.jpg" medium="image">
			<media:title type="html">visual</media:title>
		</media:content>

		<media:content url="http://globalengineer.files.wordpress.com/2009/10/block.jpg" medium="image">
			<media:title type="html">block</media:title>
		</media:content>
	</item>
		<item>
		<title>Vi: word completion</title>
		<link>http://globalengineer.wordpress.com/2009/10/29/vi-word-completion/</link>
		<comments>http://globalengineer.wordpress.com/2009/10/29/vi-word-completion/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 11:37:20 +0000</pubDate>
		<dc:creator>globalengineer</dc:creator>
				<category><![CDATA[Vi/Vim]]></category>

		<guid isPermaLink="false">http://globalengineer.wordpress.com/?p=234</guid>
		<description><![CDATA[For my new job I&#8217;m on the Linux platform, and due to the amount of software development that takes place on servers in remote locations, all of the developers on my team utilize the BASH shell, the konsole terminal program, and Vi for editing.  Though I learned the basics of Vi in college due to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=234&subd=globalengineer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>For my new job I&#8217;m on the Linux platform, and due to the amount of software development that takes place on servers in remote locations, all of the developers on my team utilize the BASH shell, the konsole terminal program, and Vi for editing.  Though I learned the basics of Vi in college due to the lack of other editors on the computer science department servers, compared to the other developers, working with Vi and the terminal feels quite clumsy to me.  I&#8217;m working on weaning myself from graphical editors and eventually enjoying the productivity boost of using a solid editor and the more advanced features of the shell.  I hope to make a regular post with tips on improving one&#8217;s productivity in Vi, BASH, and even with konsole.</p>
<p>Today I&#8217;d like to introduce <strong>word completion</strong>.  It does not require any third party extensions or libraries and it is enabled by default.  If you&#8217;re typing a word in a file or in your code that already exists somewhere in the file, type at least one letter of the word and then do the following:</p>
<blockquote><p>Cntl-n</p></blockquote>
<p>You should see a terminal-like pop-up containing all of the possible choices.  Press Cntl-n to traverse the list going downwards, and press Cntl-p to traverse the list in the opposite direction.  That is all there is to it.  It certainly helps with long_variable_names_like_this!</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/globalengineer.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/globalengineer.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/globalengineer.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/globalengineer.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/globalengineer.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/globalengineer.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/globalengineer.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/globalengineer.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/globalengineer.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/globalengineer.wordpress.com/234/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=234&subd=globalengineer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://globalengineer.wordpress.com/2009/10/29/vi-word-completion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6370396c5129eb47b3bccec6515adaaa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">globalengineer</media:title>
		</media:content>
	</item>
		<item>
		<title>C++ gotcha</title>
		<link>http://globalengineer.wordpress.com/2009/10/16/c-gotcha/</link>
		<comments>http://globalengineer.wordpress.com/2009/10/16/c-gotcha/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 16:22:47 +0000</pubDate>
		<dc:creator>globalengineer</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://globalengineer.wordpress.com/?p=229</guid>
		<description><![CDATA[I came across an amusing example in Meyers&#8217; Effective STL Item 6***.

class Widget { ... };
Widget w();


As Meyers explains,  it seems like the default constructor is called.  However, in C++ this second line is actually declaring a function &#8216;w&#8217; that takes no parameters and returns a &#8216;Widget&#8217;.  If the code author intended for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=229&subd=globalengineer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I came across an amusing example in Meyers&#8217; Effective STL Item 6***.</p>
<blockquote>
<pre>class Widget { ... };
Widget w();
</pre>
</blockquote>
<p>As Meyers explains,  it seems like the default constructor is called.  However, in C++ this second line is actually declaring a function &#8216;w&#8217; that takes no parameters and returns a &#8216;Widget&#8217;.  If the code author intended for the constructor to be called, he would have to write:</p>
<blockquote>
<pre>class Widget { ... };
Widget w;
</pre>
</blockquote>
<p>I chuckled to myself after I saw this because the former will cause the Java compiler to get angry.  This is another example of how you have to pay attention when you write C++.</p>
<p>*** I love Meyer&#8217;s works and his writing style.  He writes to you as a professional and an equal, even though he is a master.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/globalengineer.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/globalengineer.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/globalengineer.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/globalengineer.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/globalengineer.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/globalengineer.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/globalengineer.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/globalengineer.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/globalengineer.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/globalengineer.wordpress.com/229/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=229&subd=globalengineer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://globalengineer.wordpress.com/2009/10/16/c-gotcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6370396c5129eb47b3bccec6515adaaa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">globalengineer</media:title>
		</media:content>
	</item>
		<item>
		<title>Ada for C/C++ Developers: Linked List</title>
		<link>http://globalengineer.wordpress.com/2009/03/27/ada-for-cc-developers-linked-list/</link>
		<comments>http://globalengineer.wordpress.com/2009/03/27/ada-for-cc-developers-linked-list/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 08:12:23 +0000</pubDate>
		<dc:creator>globalengineer</dc:creator>
				<category><![CDATA[Ada]]></category>

		<guid isPermaLink="false">http://globalengineer.wordpress.com/?p=188</guid>
		<description><![CDATA[This installment in my Ada tutorial series is designed to show how to use records, pointers and exceptions.  Every C and C++ programmer probably remembers one of the first milestones in coming to grasp with pointers is the successful implementation of the linked list data structure.
First of all, after analyzing the source code of other [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=188&subd=globalengineer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>This installment in my Ada tutorial series is designed to show how to use records, pointers and exceptions.  Every C and C++ programmer probably remembers one of the first milestones in coming to grasp with pointers is the successful implementation of the linked list data structure.</p>
<p>First of all, after analyzing the source code of other Ada code on the Internet, it seems that the preferred method for naming variables and functions is <strong>The_Name</strong> and not <strong>TheName</strong>; use underscores instead of camel case.  Also make sure you use uppercase at the beginning of a word too.  This seems to be Ada style, so we might as well adopt it.</p>
<p>The program below should speak for itself, but I&#8217;ll just mention a few things.</p>
<ul>
<li>Records like structures in C, and that is all there is to them.  In C++ structures are really just classes and the keyword is only there for C language compatibility.</li>
<li>Recursive data structures, such as lists and trees, require forward declaration of the types.  See the program below for details, but this should not be too much of a shock as C++ requires the same unless your working with templates, and even then&#8230;</li>
<li>Exceptions will be covered more in a later tutorial, but I thought I would add it to the linked list code just to demonstrate the concept.</li>
<li>The type keyword is also introduced, but we will cover it later.  For now just know that it declares a new data type.</li>
<li>Pointers in Ada are declared using the <strong>access</strong> keyword.  I particularly like this keyword, because if you read the code, it makes sense in English.  For example,  <strong>&#8220;type Link is access Node;</strong>&#8221; can be read &#8220;type Link is access to a Node.&#8221;</li>
<li>Pointers in Ada are <em>implicitly</em> dereferenced. If you want to explicitly dereference the pointer, use <strong>Ptr.all</strong>, but let&#8217;s not worry about it for now.</li>
<li>GNAT implements garbage collection, so we can create objects and let the run-time worry about cleaning up the memory.  Note that Ada implementations are not required to support garbage collection, and most have options for disabling the garbage collection.</li>
<li>Finally, not-equal is <strong>/=</strong>, but due to Ada&#8217;s readability, you can probably figure that out from the code</li>
</ul>
<p>So, with no further delay, the source code is below.  I did test it with some simple scenarios, but I did not exhaustively test every possibility.  (possible unit testing topic in the future?)  Hopefully there are no bugs!</p>
<blockquote>
<pre>with Ada.Text_IO; use Ada.Text_IO;

procedure ListMech is
   --
   -- Define the list data structures
   --   Note: recursive data structs require forward declaration
   type Node;			-- forward declare
   type Link is access Node;	-- read literally: a "Link" accesses a "Node"

   type Node is			-- now declare the Node type
      record
         Node_Id: Integer;	-- prefer underbar to camel-case
         Next:    Link;
      end record;

   type List is
      record
         Head:   Link;		-- first node in list
         Tail:   Link;		-- last node in list
         Length: Integer := 0;	-- number of nodes in the list
      end record;

   Empty_Exception: exception;

   --
   -- Inserts an ID into the linked list
   --
   procedure Insert( Id: in Integer; Linked_List: in out List) is
   begin
      if Linked_List.Head = null then
         Linked_List.Head := new Node'(Id, null);
         Linked_List.Tail := Linked_List.Head;
         Linked_List.Length := 1;
         Put_Line("List empty =&gt; creating head node: " &amp; Integer'Image(Id));
      else
         Put_Line("Creating node: "  &amp; Integer'Image(Id));
         Linked_List.Tail.Next := new Node'(Id, null);
         Linked_List.Length := Linked_List.Length + 1;
         Linked_List.Tail := Linked_List.Tail.Next;
      end if;
   end Insert;

   --
   -- Removes and ID from the linked list (if available)
   --
   procedure Remove( Id: in Integer; Linked_List: in out List ) is
      Curr_Link: Link := Linked_List.Head;
      Prev_Link: Link := null;
      Found_Flag: Boolean := False;
   begin
      -- make sure list is not empty
      if Linked_List.Head = null then
         raise Empty_Exception;
      end if;

      while Curr_Link /= null loop
         if Curr_Link.Node_Id = Id then
            Put_Line("Removing node: "  &amp; Integer'Image(Curr_Link.Node_Id));
            if Curr_Link = Linked_List.Head then
               Linked_List.Head := Curr_Link.Next;
            else
               Prev_Link.Next := Curr_Link.Next;
            end if;
            Found_Flag := true;
            Linked_List.Length := Linked_List.Length - 1;
            exit;
         else
            Prev_Link := Curr_Link;
            Curr_Link := Curr_Link.Next;
         end if;
      end loop;

      if Found_Flag /= true then
         Put_Line("Node not in list: "  &amp; Integer'Image(Id));
      end if;
   end Remove;

   --
   -- Traverses the linked list and prints out the IDs at each node
   --
   procedure Walk( Linked_List: in List ) is
      Link_Index: Link := Linked_List.Head;
   begin
      Put_Line("Walking the list(" &amp; Integer'Image(Linked_List.Length)&amp; "): ");
      loop
         exit when Link_Index = null;
         Put_Line("--&gt; " &amp; Integer'Image(Link_Index.Node_Id));
         Link_Index := Link_Index.Next;
      end loop;
   end Walk;

   -- local variables
   Id_List: List;
   TestVector: array(Positive range &lt;&gt;) of Integer := (1, 2, 3, 4, 5);

begin

   for Index in TestVector'Range loop
      Insert( TestVector(Index), Id_List );
   end loop;
   New_Line;
   Walk( Id_List );
   New_Line;
   Remove( 1, Id_List );
   New_Line;
   Walk( Id_list );
   New_Line;
   for Index in TestVector'Range loop
      Remove( TestVector(Index), Id_List );
   end loop;

   -- list should be empty now
   New_Line;
   Remove( 9, Id_List );

exception
      when Empty_Exception =&gt; Put_Line("*** List is empty ***");
end ListMech;</pre>
</blockquote>
<p>The code is significantly longer this time, but I think we&#8217;re ready to move away from trivial programs.  After all, we&#8217;re programmers, right?  We fear nothing!</p>
<blockquote>
<pre>C:\work\ada\listmech&gt;listmech.exe
List empty =&gt; creating head node:  1
Creating node:  2
Creating node:  3
Creating node:  4
Creating node:  5

Walking the list( 5):
--&gt;  1
--&gt;  2
--&gt;  3
--&gt;  4
--&gt;  5

Removing node:  1

Walking the list( 4):
--&gt;  2
--&gt;  3
--&gt;  4
--&gt;  5

Node not in list:  1
Removing node:  2
Removing node:  3
Removing node:  4
Removing node:  5

*** List is empty ***</pre>
</blockquote>
<p>Copy the source code into an editor and try it out for yourself.  I am a better programmer than I was when I started with C++ years ago, but it felt very easy to develop this linked list code.  I&#8217;m starting to appreciate the verbosity of the syntax, the rigidity of the compiler, and the elegance of the language.  I hope you&#8217;re enjoying our endeavor too.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/globalengineer.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/globalengineer.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/globalengineer.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/globalengineer.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/globalengineer.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/globalengineer.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/globalengineer.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/globalengineer.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/globalengineer.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/globalengineer.wordpress.com/188/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=188&subd=globalengineer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://globalengineer.wordpress.com/2009/03/27/ada-for-cc-developers-linked-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6370396c5129eb47b3bccec6515adaaa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">globalengineer</media:title>
		</media:content>
	</item>
		<item>
		<title>Ada for C/C++ Developers: Development Environments</title>
		<link>http://globalengineer.wordpress.com/2009/03/27/ada-for-c-developers-development-environments/</link>
		<comments>http://globalengineer.wordpress.com/2009/03/27/ada-for-c-developers-development-environments/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 05:19:57 +0000</pubDate>
		<dc:creator>globalengineer</dc:creator>
				<category><![CDATA[Ada]]></category>

		<guid isPermaLink="false">http://globalengineer.wordpress.com/?p=182</guid>
		<description><![CDATA[Lessons Learned: Get them fresh off the boat
(Skip this anecdote if you want to get straight to work the info)
When I first started learning C/C++, it was just out of curiosity and I didn&#8217;t want to spend any money on expensive compilers.  Visual C++ and Borland C++ Builder were not cheap for a secondary school [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=182&subd=globalengineer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong>Lessons Learned: Get them fresh off the boat</strong></p>
<p>(Skip this anecdote if you want to get straight to work the info)</p>
<p>When I first started learning C/C++, it was just out of curiosity and I didn&#8217;t want to spend any money on expensive compilers.  Visual C++ and Borland C++ Builder were not cheap for a secondary school student; after all, I had just spent $30 a C++ book.  Luckily the book came with a floppy disk containg the example code and a copy of Borland Turbo C++ 4.5, an older MS-DOS C++ compiler.  It was perfect for someone like myself just getting started, and with that tool I was able to explore the world of programming: console apps, pointers, linked lists and all of that good stuff.</p>
<p>Back then Borland was a really popular compiler vendor, but at some point Microsoft tipped the scale and stole the developer tools market.  One reason that Microsoft took over is that Visual Basic proved to be easier than Delphi (&#8220;Visual Pascal&#8221;) for new programmers in the corporate world.  Another very important reason, however, is that Microsoft went after the future developers through outreach programs in academia.  When I entered the university, Microsoft sold a bundled package of Microsoft Office Professional and Microsoft Visual Studio 6.0 to incoming students for $99. All the software that we would need during our four years was available at low cost.  In my final year in school, Microsoft was giving away Visual Studio .NET for free to each student in computer science and computer engineering programs.  I can only assume they were trying to quash Java with .NET.</p>
<p>When I first looked into Ada back in 1999, there didn&#8217;t seem to be much to choose from for someone just getting started.  It seems though that the commerical Ada vendors have come to their senses and made their tools available for open-source use.  It is a matter of survival perhaps?</p>
<p><strong>Ada Development Environments</strong></p>
<p>Mostly likely you&#8217;ll be using GNAT unless your company is asking you to learn Ada on a specific vendor&#8217;s platform.  I&#8217;m not going to argue the merits of integrated development environments versus command-line development.  My personal method is to use a text editor and the command-line for small programs, and for large projects I&#8217;ll normally fall back on an IDE due to the object browsing capabilities.  When I frst started with Ada, I used the command-line and a text editor only because I felt overwhelmed by the options in the IDE.  Now that I have a better feeling for the jargon used in Ada, the IDEs make more sense and are quite usable.  If you don&#8217;t like development environments, then stop reading here and just install GNAT if you&#8217;re on UNIX or Cygwin + GNAT if you&#8217;re on Windows.</p>
<hr /><a href="https://libre.adacore.com/">GNAT Programming Studio (GPS)</a></p>
<p>GPS comes from AdaCore, the company that developers the GNAT tool chain.  If you create a free account on their Libre web page, you can then generate a custom download package that bundles not only GPS and GNAT, it also GTK+ binding, libraries for XML and CORBA, and more.  Compared to Visual Studio or Eclipse, GPS is very light-weight, and if you are comfortable with the Ada language you will become proficcient with this tool very quickly.  The only downside I see with it is that there is no auto-completion nor a &#8220;intellisense&#8221; system that displays possible choices.</p>
<p><strong>Platforms</strong>: Windows .NET, Windows x86, Linux x86, Linux86 64-bit</p>
<p><strong>Cost</strong>: (registration required) Free for open-source developers, but for commercial users a yearly subscription is required</p>
<p><strong>Opinion</strong>: the best IDE available to non-commercial users</p>
<p><img class="aligncenter size-medium wp-image-183" title="gps" src="http://globalengineer.files.wordpress.com/2009/03/gps.jpg?w=300&#038;h=249" alt="gps" width="300" height="249" /></p>
<hr /><a href="http://sourceforge.net/projects/adagide/">AdaGIDE</a></p>
<p>AdaGIDE was the popular IDE before GPS was made available to open-source developers. While it resembles Emacs visually, it is a regular editor and you don&#8217;t have to memorize a bunch of Ctrl or Alt key combinations.  AdaGIDE supports integration with GNAT, syntax highlighting, and all of the features needed for developing small Ada software projects.</p>
<p><strong>Platforms</strong>: Windows</p>
<p><strong>Cost</strong>: free</p>
<p><strong>Opinion</strong>:  a light-weight IDE that should suit the needs for any hobbyists running on older hardware</p>
<hr /><a href="https://libre.adacore.com/GNATbench/">GNATBench</a></p>
<p>Also AdaCore, GNATBench is simply a plug-in for the popular Eclipse IDE.  It uses an exisiting install of GNAT on your machine, and then utilizes Eclipse to manage, edit and build your software.  I had high-hopes for this plug-in because unlike GPS, GNATBench has an &#8220;intellisense&#8221; like-feature.  Though it was easy to install this plug-in in my existing Eclipse setup, Eclipse reported errors and Java run-time exceptions after I started editing some Ada source files.  I don&#8217;t know where the fault is, but I never get such errors when I edit Erlang files in ErlIDE.  I want to write code and solve problems, not debug Eclipse, so I am not using this tool anymore.</p>
<p><strong>Platforms</strong>: any platform that supports both Eclipse and GNAT</p>
<p><strong>Cost</strong>: free</p>
<p><strong>Opinion</strong>: a lot of potential, but still too unstable for my liking</p>
<p><img class="aligncenter size-medium wp-image-184" title="eclipse" src="http://globalengineer.files.wordpress.com/2009/03/eclipse.jpg?w=300&#038;h=223" alt="eclipse" width="300" height="223" /></p>
<hr /><a href="http://www.eclipse.org/hibachi/">Hibachi ADT</a> &#8211; unavailable</p>
<p>As far as I can tell, this is a project that was suposed to take off and fill a gap in the market, but it appears dead in the water since 1997.  Perhaps Aonix&#8217;s and AdaCore&#8217;s plug-ins have caused the developers of this project to hang up their shoes?</p>
<p><strong>Opinion</strong>: Noting really to say, it seems like a dead project</p>
<hr /><a href="http://www.cygwin.com/">Cygwin</a> &#8211; not really and development envirnoment&#8230;but an option</p>
<p>I don&#8217;t think the Cygwin project needs any introduction.  If you want a UNIX-like environment to develop Ada programs in, simply select the GNAT binaries during installation and you should be set to go.  Edit Ada files with your favorite text editor, debug with GDB &#8212; it should all be familiar.</p>
<p><strong>Platforms</strong>: Windows</p>
<p><strong>Cost</strong>: free</p>
<p><strong>Opinion</strong>:  If you know UNIX, this is a great way to get started with Ada and learn the build process</p>
<hr /><a href="http://www.aonix.com/adt.html">AonixADT</a></p>
<p>Aonix has their own Ada compiler called ObjectAda, and AonixADT is a plug-in for Eclipse that can be used with ObjectAda or GNAT. I have downloaded the plug-in, but I have not installed it or evaluated it yet.  The build data is 2007, and here we are in 2009?  I&#8217;m a bit skeptical of Eclipse plug-ins that don&#8217;t keep up with the times.  I blame Mentor and their Nucleus RTOS development environment for this skepticism.</p>
<p><strong>Platforms</strong>: any that support Eclipse and ObjectAda or GNAT</p>
<p><strong>Cost</strong>: (registration required) free</p>
<p><strong>Opinion</strong>: none yet, I haven&#8217;t tried this one</p>
<hr /><a href="http://www.praxis-his.com/sparkada/index.asp">SPARKAda</a></p>
<p>SPARK is a subset of the Ada language as well as a platform that is quite popular in the commercial Ada development community.  A lot of PR about Ada in the news these days revolves around SPARK, such as the <a href="http://www.praxis-his.com/news/TokeneerNews.asp">NSA Tokeneer</a> [<a href="http://www.ddj.com/architect/212001533">DrDobbs</a>, <a href="http://www.adacore.com/home/products/gnatpro/tokeneer/">AdaCore</a>] project. From the <a href="http://www.praxis-his.com/sparkada/intro.asp">vendor&#8217;s web page</a>:</p>
<blockquote><p>SPARK gives confidence in the correctness of code –                      it is verifiable. Early detection and prevention of defects                      reduces the cost of verification and validation. SPARK is                      a very portable language and has minimal runtime system requirements.</p></blockquote>
<p>SPARK is a commercial tool aimed at real systems and embedded platforms, so there is no free version for developing application software.  <a href="http://www.praxis-his.com/sparkada/sparkbook.asp">A demo version for training and education</a> is available, however.</p>
<p><strong>Platforms</strong>: Demo version is available for Windows, Linux, Mac OS X 10.4</p>
<p><strong>Cost</strong>: (registration required) free demo version; contact sales for the commercial package</p>
<p><strong>Opinion</strong>:  none yet, though I should take a look at the demo version sooner or later</p>
<hr />There are probably other development environments available, especially in the commercial realm, but the above were the ones that turned up at the top of Google searches when I was researching the Ada development environment terrain.  While all are not quite as polished as Visual Studio or NetBeans, it is definately a good start!</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/globalengineer.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/globalengineer.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/globalengineer.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/globalengineer.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/globalengineer.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/globalengineer.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/globalengineer.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/globalengineer.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/globalengineer.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/globalengineer.wordpress.com/182/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=182&subd=globalengineer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://globalengineer.wordpress.com/2009/03/27/ada-for-c-developers-development-environments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6370396c5129eb47b3bccec6515adaaa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">globalengineer</media:title>
		</media:content>

		<media:content url="http://globalengineer.files.wordpress.com/2009/03/gps.jpg?w=300" medium="image">
			<media:title type="html">gps</media:title>
		</media:content>

		<media:content url="http://globalengineer.files.wordpress.com/2009/03/eclipse.jpg?w=300" medium="image">
			<media:title type="html">eclipse</media:title>
		</media:content>
	</item>
		<item>
		<title>Ada for C/C++ Developers: Wide Characters</title>
		<link>http://globalengineer.wordpress.com/2009/03/24/ada-for-c-developers-wide-characters/</link>
		<comments>http://globalengineer.wordpress.com/2009/03/24/ada-for-c-developers-wide-characters/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 03:41:49 +0000</pubDate>
		<dc:creator>globalengineer</dc:creator>
				<category><![CDATA[Ada]]></category>

		<guid isPermaLink="false">http://globalengineer.wordpress.com/?p=162</guid>
		<description><![CDATA[Originally, the Ada language only supported the ISO-8859-1 encoding, which is capable of handling most of the characters in Western European languages. I suppose that was acceptable in the 80s, and even in the late 90s perhaps as most of the users of Ada seem to come from the USA, UK, Germany and France.  But [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=162&subd=globalengineer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Originally, the Ada language only supported the ISO-8859-1 encoding, which is capable of handling most of the characters in Western European languages. I suppose that was acceptable in the 80s, and even in the late 90s perhaps as most of the users of Ada seem to come from the USA, UK, Germany and France.  But in the 21st century?  No way, completely unacceptable!</p>
<p>Ada 2005 added support for wide characters so that your application can support languages such as Chinese, Russian and Arabic.  It also also added support for UTF-8 file encoding. As a C++ developer who has struggled with internationalization issues, particularly reading UTF-8 text files, I truly welcome this support in Ada. I may not have the latest information, but I don&#8217;t believe C++ supports UTF-8 without the help of third party libraries.  Perhaps that will change in C++0x?</p>
<p>Working with wide characters in Ada is no more difficult than it is in C++.  Separate I/O libraries are provided for regular and wide text, just like in C++ (wcout/wcin, wsprintf, etc).  For example, <strong>Ada.Wide_Text_IO</strong> is the wide character equivalent of <strong>Ada.Text_IO</strong>.  I should also mention that unlike C++, Ada 2005 allows a developer to define variables  and types using languages like Chinese or Hebrew.  Though I doubt (perhaps naively) that this is utilized very often, it is interesting nonetheless.  Please note that:</p>
<ul>
<li><strong>Ada.Strings.Unbounded</strong> and <strong>Ada.Strings.Bounded</strong> are similar to the <strong>std::string</strong> and <strong>char []</strong> arrays in C++</li>
<li><strong>Ada.Strings.Wide_Unbounded</strong> and <strong>Ada.Strings.Wide_Bounded</strong> and are similar to the <strong>std::wstring</strong> and<strong> wchar_t []</strong> arrays in C++.</li>
</ul>
<p>Here is an extremely simple program to demonstrate the use of wide characters with Russian and Chinese.  If you are copying and pasting this to an editor, make sure to save the file in UTF-8 format or you might loose the Chinese and Russian text.</p>
<blockquote>
<pre>with Ada.Wide_Text_IO;
use Ada.Wide_Text_IO;

procedure WideText is
	Msg1: Wide_String := "Россия";
	Msg2: Wide_String := "中国";
begin
	Put_Line(Msg1);
	Put_Line(Msg2);
end WideText;</pre>
</blockquote>
<p>The Msg1 variable holds the Cyrillic for &#8220;Russia&#8221;, and the Msg2 variable holds the Chinese for &#8220;China&#8221;.  My test environment is Cygwin on Windows, and unfortunately, I have not figured out how to get unicode to display properly in the terminal.  Perhaps someone on a Linux box with a UTF-8 terminal could very this?  If you&#8217;re in the same boat as me, then just dump the output to a file and open it up in a unicode-friendly editor.</p>
<blockquote><p>./widetext.exe &gt; output.txt</p></blockquote>
<p>You should be able to see both strings on a separate line in the file:</p>
<blockquote><p>Россия<br />
中国</p></blockquote>
<p>If someone ever figures out unicode in the cygwin terminal or Windows cmd.exe terminal, please let me know!</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/globalengineer.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/globalengineer.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/globalengineer.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/globalengineer.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/globalengineer.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/globalengineer.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/globalengineer.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/globalengineer.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/globalengineer.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/globalengineer.wordpress.com/162/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=162&subd=globalengineer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://globalengineer.wordpress.com/2009/03/24/ada-for-c-developers-wide-characters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6370396c5129eb47b3bccec6515adaaa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">globalengineer</media:title>
		</media:content>
	</item>
		<item>
		<title>Ada for C/C++ Developers: A first program</title>
		<link>http://globalengineer.wordpress.com/2009/03/19/ada-for-cc-developers-a-first-program/</link>
		<comments>http://globalengineer.wordpress.com/2009/03/19/ada-for-cc-developers-a-first-program/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 06:57:09 +0000</pubDate>
		<dc:creator>globalengineer</dc:creator>
				<category><![CDATA[Ada]]></category>

		<guid isPermaLink="false">http://globalengineer.wordpress.com/?p=160</guid>
		<description><![CDATA[
<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=160&subd=globalengineer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>After feeling a bit overwhelmed with <a href="http://www.springer.com/computer/book/978-1-84882-313-6">Ada for Software Engineers</a>, I decided to take a break and try to write some simple programs so that I can get more familiar with the core Ada language.  Hopefully these entries will help any one else interested in Ada.</p>
<p>The following is a sample program I created to become accustomed with the some basics of Ada: console I/O, arrays, and most importantly,  strings.</p>
<blockquote>
<pre>with Ada.Text_IO;
with Ada.Strings;
with Ada.Characters.Latin_1;
use  Ada.Text_IO;

procedure Reverser is

	procedure ReverseIt
		( Text: in String;
                  Len:  in Integer  )
	is
	begin
		for Index in reverse Text'First .. Len loop
			Put(Text(Index));
		end loop;
		Put(Ada.Characters.Latin_1.CR);
		Put(Ada.Characters.Latin_1.LF);
	end ReverseIt;

	Input:    String(1..255);
	Last:     Integer;
begin
	loop
		Put("&gt;&gt; ");
		Get_Line(Input, Last);
		exit when Input(1) = Ada.Characters.Latin_1.ESC;
		ReverseIt(Input, Last);
	end loop;
end Reverser;</pre>
</blockquote>
<p>First of all, Ada is case insensitive, but good Ada style dictates that we name variables and functions with upper-case letters. I have yet to find out whether camel case (ReverseIt) or underbars (Reverse_It) are preferred for nameing variables and functions that have mulitple words.  Before I forget, I should also mention that array indeces start from one is Ada, not zero like in C++.</p>
<p>Ada is quite verbose and easy to read even if you don&#8217;t know the syntax.  Without know the details of the syntax, a developer familiar with basic procedural programming should have no trouble understanding what this simple program does.  It simply reads a string from the user and prints it out reversed on the string.</p>
<p>For a C++ programmer, the syntax is quiet different though.  In the definition of the ReverseIt procedure, each parameter in the parameter list is labed as <strong>in</strong> before the type is listed.  <strong>&#8220;Len: in Integer&#8221;</strong> is equivalent to <strong>&#8220;const int Len&#8221;</strong> in C++.  For ouputs we can use <strong>out</strong>, which would be similar to &#8220;int &amp;Len&#8221; and for parameters that function as both inputs and outputs, we can use <strong>inout</strong>.</p>
<p>The <strong>with </strong>clauses are like #include statements in C++ in that they allow our program to call functions from external libraries.  <strong>Ada.Text_IO</strong> and <strong>Ada.String</strong> libraries are  similar to <strong>cstdio</strong> and <strong>cstring</strong> respectively.  Ada.String is for fixed length strings like C-style character arrays.  The <strong>use</strong> clause is similar to the C++ namespace statement as it brings the library into scope and allows us to leave off the library name when calling a function from the library.  Instead of using <strong>Ada.Text_IO.Get_Line</strong> in the program we can simply use <strong>Get_Line</strong>. It might also be a good idea to take a look at the Ada.Text_IO library to better understand how to use the I/O functions.</p>
<p>The final thing to be wary of is semicolons in the parameter list for the ReverseIt procedure.  The last parameter for the procedure does NOT have a semicolon. If you place a semicolon at the end of the statement, GNAT will become angry with you.  My advice is to always complete the parenthesis first and then go back and fill in the parameters as necessary.</p>
<p>Other oddities for the C++ programmer might be that both local variables and procedures/functions are declared before the main program body is defined.  Also, the Ada.Characters.Latin_1 library is <strong>with</strong>ed so that we use control characters like carriage return (CR), line-feed (LF) and escape (ESC).  These are the equivalent of escape characters such as  &#8220;\n&#8221; or &#8220;\r&#8221; in C++.  If you look at the .ads file for the Latin_1 library, you can see it simply defines a bunch of character constansts with the proper ASCII values.</p>
<p>Finally, note that there is no main function defined in the code.  Unlike the C++ run-time, the Ada run-time does not require the entry point of the program to be named &#8220;main&#8221;.  However, the entry point procedure should be the same as the file name.  In this case, the entry point is the Reverser procedure, which is why the file is named reverser.adb.</p>
<p>To build this program, first copy the program code into your favorite editor and save it as <strong>reverser.adb</strong>.  GNAT expects program bodies to end in the suffix .adb.  It expects specifications&#8211;like C++ header files&#8211;to end in the .ads suffix.  For now lets not worry about specifications as our programs will be simple in the beginning.  We can either run the single-step build process, or we can build it separate steps.  Execute &#8220;gnatmake reverser.adb&#8221; on the command line to runt he single-step process.  If there are no errors, the reverser binary is created in your working directory.</p>
<p>For learning purposes though, lets build the program step-by-step.  To start, execute the following on the command line:</p>
<blockquote><p>gnatmake -c reverser.adb</p></blockquote>
<p>If you look in your working directory, reverser.o and reverser.ali have been created.  On the screen you probably noticed that the above command actually invoked &#8220;gcc -c reverser.adb&#8221;.  The GNU compiler supports not only C/C++, but also languages like Objective-C and Ada.  Just as in C++, after compiling the program, an object file, reverser.o, is created. The <a href="http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/The-Ada-Library-Information-Files.html">GNAT manual explains the Ada Library Info (ALI) file</a> in more depth, but it essentially holds information about required libraries and version information.</p>
<p>The next step is to <a href="http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Binding-an-Ada-Program.html#Binding-an-Ada-Program">bind the program</a>.  The binding process uses information from ALI and object files to make sure that package (modules) versions match and that there are no inconsistencies.  There is no equivalent in C++, and binding is touted by Ada developers as yet another way that Ada is inherently safer than C/C++ programs.  To bind the application, execute the following:</p>
<blockquote><p>gnatbind reverser</p></blockquote>
<p>We do not need to specify the ALI file with its suffix because the binder figures it out. The bind process produces two files, b~reverser.ads and b~reverser.adb.  Take a look at the contents of the files&#8211;quite a bit of information in there!  Refer to the GNAT manual if you want to know more, but lets move on and worry about the details later.</p>
<p>The final step is to link the program with required libraries to produce an executable (just like we do in C++).</p>
<blockquote><p>gnatlink reverser</p></blockquote>
<p>Take a look at the working directory.  Notice that the gnatbind output is now removed and that there is also an executable for our program.</p>
<p>So that is it for our first program.  If the program doesn&#8217;t make any sense, spend some time looking at the library specifications.  For further enrichment, try changing things in the program such as outputing past the length of the input string or passing bad arguments.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/globalengineer.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/globalengineer.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/globalengineer.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/globalengineer.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/globalengineer.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/globalengineer.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/globalengineer.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/globalengineer.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/globalengineer.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/globalengineer.wordpress.com/160/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=160&subd=globalengineer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://globalengineer.wordpress.com/2009/03/19/ada-for-cc-developers-a-first-program/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6370396c5129eb47b3bccec6515adaaa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">globalengineer</media:title>
		</media:content>
	</item>
		<item>
		<title>Reflections on the Ada Language</title>
		<link>http://globalengineer.wordpress.com/2009/03/10/reflections-on-the-ada-language/</link>
		<comments>http://globalengineer.wordpress.com/2009/03/10/reflections-on-the-ada-language/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 03:03:10 +0000</pubDate>
		<dc:creator>globalengineer</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://globalengineer.wordpress.com/?p=152</guid>
		<description><![CDATA[I go through periods where I have a crave to learn new programming technology.  I&#8217;ve tried Java in the past, but in the end I fell back on C++.  Same thing for Python and Haskell&#8211;the syntax (sorry, freedom with white-space is just a personal preference!) and lack of familiarity with the libraries led me back [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=152&subd=globalengineer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I go through periods where I have a crave to learn new programming technology.  I&#8217;ve tried Java in the past, but in the end I fell back on C++.  Same thing for Python and Haskell&#8211;the syntax (sorry, freedom with white-space is just a <strong><em>personal</em></strong> preference!) and lack of familiarity with the libraries led me back to C++.  But sometimes I want to try something new and feel that &#8220;wow&#8221; moment when you really appreciate a new way of doing something.  So far only Erlang has managed to cause that reaction.  I still need to have a go at Eiffel one of these days.  The software engineering aspect of Eiffel looks really interesting.</p>
<p>Speaking of software engineering, I have always been interested in evaluating Ada and understanding the how and why it is known for safety and reliability.  I have been trying to make myself more comfortable with Ada since my days in the university.  After all, unlike Java, C# or many modern languages, Ada is not managed and I can use the GNU tool chain for development and debugging.  Yet somehow Ada never sticks to me&#8211;I don&#8217;t know why.  Ada is used in some of the most interesting software in the world: avionics, rail transport control in the EU, satellites, and more.  Even with such an impressive track record, I still find it difficult to buckle down and really go at Ada!  Those applications are so much more interesting that what I currently work on.</p>
<p>Whenever someone in the Ada community publishes and article about the strength of Ada in software engineering and the lack of developers who know the language, I get the urge to try and pick it up again.  I really want to understand what makes it so well suited for mission critical applications, yet when I start reading a book on Ada, I loose interest in a few days.</p>
<p>One major factor may be that I cannot really use it in my job. I could, but my boss would probably throw a telephone book at me if he wanted to update my software and found it was not C, C++ or C#.</p>
<p>I just cannot put my finger on it though.  I don&#8217;t mind that Ada is a verbose language&#8211;it helps to keep my C/C++ style of thinking out of any Ada code.  Reflecting on my FPGA designs, when I write Verilog (required at work) I sometimes catch myself writing it like a C program.  I never had that issue with VHDL (from my school days)  because the syntax is just so different from C&#8211;in fact, VHDL is based on Ada.</p>
<p>So why the personal trouble with Ada?   Am I just not motivated enough?  Perhaps.  Honestly, I think the biggest hurdle for me with Ada is the constant reference to the ARM, the Ada Reference Manual, in Ada learning materials.  I understand that the ARM is a &#8220;contract&#8221; and Ada programmers should refer to it when it doubt.  However, it has to be the driest reading I&#8217;ve ever attempted&#8211;even my undergraduate electromagnetics textbook was more interesting! In &#8220;Ada for Software Engineers&#8221;, I can feel myself nodding off whenever a reference/quote is made to the ARM.</p>
<p>Perhaps the reverence for the ARM is the difference between Ada and other languages.  When I first learned C++, I learned little-by-little, and as I gained more experience and felt more confident in my ability to write C++, I could then attempt to read Stroustrup&#8217;s C++ book and Lippman&#8217;s C++ Object Model book.  I was at the level where I really could understand C++ and I could understand how it worked under the hood.  Perhaps I should try some other Ada books, I don&#8217;t know.</p>
<p>Nonetheless, I still toy around with the language during downtime.  I often wonder if there are there any interesting open-source Ada projects out there?  It always helps to see how a language is applied.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/globalengineer.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/globalengineer.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/globalengineer.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/globalengineer.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/globalengineer.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/globalengineer.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/globalengineer.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/globalengineer.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/globalengineer.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/globalengineer.wordpress.com/152/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=152&subd=globalengineer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://globalengineer.wordpress.com/2009/03/10/reflections-on-the-ada-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6370396c5129eb47b3bccec6515adaaa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">globalengineer</media:title>
		</media:content>
	</item>
		<item>
		<title>Helpful DSP Articles</title>
		<link>http://globalengineer.wordpress.com/2009/02/16/helpful-dsp-articles/</link>
		<comments>http://globalengineer.wordpress.com/2009/02/16/helpful-dsp-articles/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 10:43:09 +0000</pubDate>
		<dc:creator>globalengineer</dc:creator>
				<category><![CDATA[DSP]]></category>

		<guid isPermaLink="false">http://globalengineer.wordpress.com/?p=140</guid>
		<description><![CDATA[I just thought I&#8217;d share this link: Top DSP how-to&#8217;s of 2008 from DSP Design Line.  There is some really good stuff in there, and it is also a good source for reviewing your DSP concepts.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=140&subd=globalengineer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I just thought I&#8217;d share this link: <a href="http://www.dspdesignline.com/howto/212500211">Top DSP how-to&#8217;s of 2008</a> from DSP Design Line.  There is some really good stuff in there, and it is also a good source for reviewing your DSP concepts.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/globalengineer.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/globalengineer.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/globalengineer.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/globalengineer.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/globalengineer.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/globalengineer.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/globalengineer.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/globalengineer.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/globalengineer.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/globalengineer.wordpress.com/140/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=globalengineer.wordpress.com&blog=2361522&post=140&subd=globalengineer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://globalengineer.wordpress.com/2009/02/16/helpful-dsp-articles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6370396c5129eb47b3bccec6515adaaa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">globalengineer</media:title>
		</media:content>
	</item>
	</channel>
</rss>