<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>Ada Programming Language Tips</title><link>https://ada.tips/</link><description></description><lastBuildDate>Sat, 02 Sep 2017 16:44:00 +0300</lastBuildDate><item><title>Declaring subtypes of private types</title><link>https://ada.tips/declaring-subtypes-of-private-types.html</link><description>&lt;p&gt;Sometimes, you want to declare a subtype for a subset of the possible values of a private type.&lt;/p&gt;
&lt;p&gt;You might for example want a subtype of &lt;cite&gt;Ada.Calendar.Time&lt;/cite&gt;, which only can include times in the past.  If &lt;cite&gt;Ada.Calendar.Time&lt;/cite&gt; was a numeric type, we could declare a subset …&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jacob Sparre Andersen</dc:creator><pubDate>Sat, 02 Sep 2017 16:44:00 +0300</pubDate><guid isPermaLink="false">tag:ada.tips,2017-09-02:/declaring-subtypes-of-private-types.html</guid><category>misc</category><category>contracts</category><category>private types</category><category>predicates</category></item><item><title>Building a VCS status package with Gprbuild</title><link>https://ada.tips/building-a-vcs-status-package-with-gprbuild.html</link><description>&lt;p&gt;Would you like your executable files to be able to tell which commit in
your version control system it corresponds to?&lt;/p&gt;
&lt;p&gt;You can do it by:&lt;/p&gt;
&lt;ol class="arabic simple"&gt;
&lt;li&gt;Creating a program (in this example a shell script), which generates
Ada source files reporting the version control status.&lt;/li&gt;
&lt;li&gt;Defining a &amp;quot;language&amp;quot; in Gprbuild …&lt;/li&gt;&lt;/ol&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jacob Sparre Andersen</dc:creator><pubDate>Tue, 21 Feb 2017 19:30:00 +0200</pubDate><guid isPermaLink="false">tag:ada.tips,2017-02-21:/building-a-vcs-status-package-with-gprbuild.html</guid><category>gprbuild</category><category>version control</category><category>code generation</category><category>gprbuild</category></item><item><title>Using Ada.Sequential_IO to create simple hexdump utility</title><link>https://ada.tips/using-adasequential_io-to-create-simple-hexdump-utility.html</link><description>&lt;p&gt;There is every now and then need for viewing the file contents
as &amp;quot;raw&amp;quot; bytes shown as hex numbers. Usually, operating systems
have tool 'hexdump' to do this. But it is not hard to create
one from scratch.&lt;/p&gt;
&lt;p&gt;Here is one example how to create a simple hexdump utility in …&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tero Koskinen</dc:creator><pubDate>Mon, 26 Dec 2016 12:00:00 +0200</pubDate><guid isPermaLink="false">tag:ada.tips,2016-12-26:/using-adasequential_io-to-create-simple-hexdump-utility.html</guid><category>misc</category><category>sequential_io</category><category>hexdump</category></item><item><title>Case statements in Ada (video)</title><link>https://ada.tips/case-statements-in-ada-video.html</link><description>&lt;p class="first last"&gt;Case statements and compile-time coverage checking Ada&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jacob Sparre Andersen</dc:creator><pubDate>Sat, 01 Aug 2015 18:00:00 +0300</pubDate><guid isPermaLink="false">tag:ada.tips,2015-08-01:/case-statements-in-ada-video.html</guid><category>video</category><category>case statements</category><category>static analysis</category><category>compile-time checks</category></item><item><title>Create multiple instances of same package using parameterless generics</title><link>https://ada.tips/create-multiple-instances-of-same-package-using-parameterless-generics.html</link><description>&lt;p&gt;There are some cases when you want to create and use multiple instances
of same package.&lt;/p&gt;
&lt;p&gt;This is easily done by creating a generic package which does not take any
parameters:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
generic
package Counter is
   function Get_Number return Natural;
end Counter;

package body Counter is
   Counter_Value : Natural := 0;

   function Get_Number …&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tero Koskinen</dc:creator><pubDate>Fri, 10 Jul 2015 17:00:00 +0300</pubDate><guid isPermaLink="false">tag:ada.tips,2015-07-10:/create-multiple-instances-of-same-package-using-parameterless-generics.html</guid><category>misc</category><category>generics</category></item><item><title>Use Ada 2012 aspects to specify variable locations</title><link>https://ada.tips/use-ada-2012-aspects-to-specify-variable-locations.html</link><description>&lt;p&gt;Earlier with Ada 95 and Ada 2005, if you wanted to
put a variable to some specific memory location,
you had to use 'for Variable'Address use X' statement
and Volatile pragma for that:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
My_Var : Unsigned_32;
for My_Var'Address use System'To_Address (16#FF00#);
pragma Volatile (My_Var);
&lt;/pre&gt;
&lt;p&gt;With Ada 2012 this becomes simpler …&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tero Koskinen</dc:creator><pubDate>Fri, 16 Jan 2015 23:00:00 +0200</pubDate><guid isPermaLink="false">tag:ada.tips,2015-01-16:/use-ada-2012-aspects-to-specify-variable-locations.html</guid><category>embedded</category><category>aspects</category><category>ada2012</category></item><item><title>Using quotation mark easily in Strings</title><link>https://ada.tips/using-quotation-mark-easily-in-strings.html</link><description>&lt;p&gt;Did you know that you can easily use quotation marks inside String literals
by typing the quotation mark &lt;a class="reference external" href="http://www.adaic.org/resources/add_content/standards/05rm/html/RM-2-6.html"&gt;twice&lt;/a&gt;?&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;Put_Line&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;Hello, &amp;quot;&amp;quot;anonymous&amp;quot;&amp;quot; person!&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tero Koskinen</dc:creator><pubDate>Sat, 11 Oct 2014 16:00:00 +0300</pubDate><guid isPermaLink="false">tag:ada.tips,2014-10-11:/using-quotation-mark-easily-in-strings.html</guid><category>quickies</category><category>strings</category></item><item><title>Self-referencing Objects</title><link>https://ada.tips/self-referencing-objects.html</link><description>&lt;p&gt;One may in some cases want an object to contain a reference (&lt;cite&gt;'Access&lt;/cite&gt;) to
itself.&lt;/p&gt;
&lt;p&gt;The package &lt;cite&gt;Self_Referencing_Objects&lt;/cite&gt; shows how one can implement
(consistently) self-referencing objects using limited records and
discriminants.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="kt"&gt;Instance&lt;/span&gt; &lt;span class="kr"&gt;is&lt;/span&gt; &lt;span class="kr"&gt;limited&lt;/span&gt; &lt;span class="kd"&gt;private&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="kt"&gt;Holder&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;Reference&lt;/span&gt; &lt;span class="p"&gt;: &lt;/span&gt;&lt;span class="nv"&gt;access&lt;/span&gt; &lt;span class="nv"&gt;Instance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kr"&gt;is&lt;/span&gt; &lt;span class="kr"&gt;limited&lt;/span&gt; &lt;span class="kr"&gt;null record&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="kt"&gt;Instance&lt;/span&gt; &lt;span class="kr"&gt;is&lt;/span&gt; &lt;span class="kr"&gt;limited&lt;/span&gt;
   &lt;span class="kr"&gt;record …&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jacob Sparre Andersen</dc:creator><pubDate>Thu, 21 Aug 2014 08:00:00 +0300</pubDate><guid isPermaLink="false">tag:ada.tips,2014-08-21:/self-referencing-objects.html</guid><category>misc</category><category>self-reference</category></item><item><title>Using discriminated records to return variable amount of data from function</title><link>https://ada.tips/using-discriminated-records-to-return-variable-amount-of-data-from-function.html</link><description>&lt;p&gt;Sometimes, you want to return different data from a function dependending on the given parameters and the program state.
For example, when searching a container for a certain element, you either want to return &amp;quot;NOT_FOUND&amp;quot; information
or the actual element.&lt;/p&gt;
&lt;p&gt;One way to do this is to use &lt;a class="reference external" href="http://www.ada-auth.org/standards/12rm/html/RM-3-7.html"&gt;discriminated&lt;/a&gt; (or …&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tero Koskinen</dc:creator><pubDate>Tue, 12 Aug 2014 23:45:00 +0300</pubDate><guid isPermaLink="false">tag:ada.tips,2014-08-12:/using-discriminated-records-to-return-variable-amount-of-data-from-function.html</guid><category>misc</category><category>functions</category><category>records</category><category>discriminants</category></item><item><title>Easy way to create portable bindings to opaque C types</title><link>https://ada.tips/easy-way-to-create-portable-bindings-to-opaque-c-types.html</link><description>&lt;p&gt;Have you ever struggled to create bindings for
C types like FILE or &lt;a class="reference external" href="http://curl.haxx.se/libcurl/c/curl_easy_init.html"&gt;CURL&lt;/a&gt;? If yes, then you know
how hard it can be, since the type might not be
same on all platforms.&lt;/p&gt;
&lt;p&gt;Easy solution for these is to define a null record
which represents the type and use …&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tero Koskinen</dc:creator><pubDate>Tue, 06 May 2014 21:45:00 +0300</pubDate><guid isPermaLink="false">tag:ada.tips,2014-05-06:/easy-way-to-create-portable-bindings-to-opaque-c-types.html</guid><category>misc</category><category>bindings</category><category>c_language</category><category>curl</category></item><item><title>Checking file header with Adacontrol</title><link>https://ada.tips/checking-file-header-with-adacontrol.html</link><description>&lt;p&gt;Many times you want to make sure that your code has correct comment block at the beginning of the source code file.
This comment block can contain the source code license, copyright information, the name of the author, or description
of the file.&lt;/p&gt;
&lt;p&gt;Adacontrol can help you here with its …&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tero Koskinen</dc:creator><pubDate>Thu, 27 Mar 2014 22:30:00 +0200</pubDate><guid isPermaLink="false">tag:ada.tips,2014-03-27:/checking-file-header-with-adacontrol.html</guid><category>adacontrol</category><category>license</category><category>header</category><category>codereview</category></item><item><title>Redirecting Text_IO output to a file</title><link>https://ada.tips/redirecting-text_io-output-to-a-file.html</link><description>&lt;p&gt;One, probably not so often used, feature of Ada.Text_IO is an ability to
redirect output (Put, Put_Line, Newline) to a file. It happens simply
by opening a file where you want to redirect the output and then calling
Set_Output procedure.&lt;/p&gt;
&lt;p&gt;Example below shows how it is done:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kn"&gt;with&lt;/span&gt; &lt;span class="nn"&gt;Ada …&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tero Koskinen</dc:creator><pubDate>Fri, 14 Mar 2014 22:30:00 +0200</pubDate><guid isPermaLink="false">tag:ada.tips,2014-03-14:/redirecting-text_io-output-to-a-file.html</guid><category>misc</category><category>text_io</category></item><item><title>Checking "out" parameters with Adacontrol</title><link>https://ada.tips/checking-out-parameters-with-adacontrol.html</link><description>&lt;p&gt;Have you ever accidentally written code like this?&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kd"&gt;procedure&lt;/span&gt; &lt;span class="nf"&gt;Example_Proc&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;X&lt;/span&gt; &lt;span class="p"&gt;: &lt;/span&gt;&lt;span class="nv"&gt;out&lt;/span&gt; &lt;span class="nv"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kr"&gt;is&lt;/span&gt;
&lt;span class="kr"&gt;begin&lt;/span&gt;
   &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;-- Do something, but do not touch X&lt;/span&gt;
&lt;span class="kr"&gt;end&lt;/span&gt; &lt;span class="nf"&gt;Example_Proc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;with&lt;/span&gt; &lt;span class="nn"&gt;Example_Proc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;procedure&lt;/span&gt; &lt;span class="nf"&gt;Main&lt;/span&gt; &lt;span class="kr"&gt;is&lt;/span&gt;
   &lt;span class="n"&gt;My_Flag&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kr"&gt;begin&lt;/span&gt;
   &lt;span class="n"&gt;Example_Proc&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;My_Flag&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kr"&gt;end&lt;/span&gt; &lt;span class="nf"&gt;Main&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In the above code, parameter X with mode &amp;quot;out&amp;quot; is left untouched.
Because …&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tero Koskinen</dc:creator><pubDate>Sat, 08 Mar 2014 21:45:00 +0200</pubDate><guid isPermaLink="false">tag:ada.tips,2014-03-08:/checking-out-parameters-with-adacontrol.html</guid><category>adacontrol</category><category>parameters</category><category>codereview</category></item><item><title>Opening a web page using default browser with Ada on Windows</title><link>https://ada.tips/opening-a-web-page-using-default-browser-with-ada-on-windows.html</link><description>&lt;p class="first last"&gt;Open a web page on Windows using Ada&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tero Koskinen</dc:creator><pubDate>Mon, 03 Mar 2014 23:00:00 +0200</pubDate><guid isPermaLink="false">tag:ada.tips,2014-03-03:/opening-a-web-page-using-default-browser-with-ada-on-windows.html</guid><category>misc</category><category>windows</category><category>url</category><category>browser</category></item></channel></rss>