Differences

This shows you the differences between two versions of the page.

Link to this comparison view

ada.calendar.clock_to_string [2012/01/03 21:44]
thomaslocke [Introduction]
ada.calendar.clock_to_string [2012/01/03 21:48] (current)
thomaslocke [A Full Program]
Line 5: Line 5:
 =====  Caveat ​ ===== =====  Caveat ​ =====
  
-The following ​is an example ​of how to do something. It's not meant to be used in any real capacity. If you need a portable [[http://​adaic.org/​standards/​05rm/​html/​RM-3-6-3.html#​I1889|String]] representation of [[http://​adaic.org/​standards/​05rm/​html/​RM-9-6.html#​I3747|Ada.Calendar.Clock]],​ then you're better off using the many nice features of [[http://​adaic.org/​standards/​05rm/​html/​RM-9-6-1.html#​I3773|Ada.Calendar.Formatting]].+The following ​are examples ​of how to do something. It's not meant to be used in any real capacity. If you need a portable [[http://​adaic.org/​standards/​05rm/​html/​RM-3-6-3.html#​I1889|String]] representation of [[http://​adaic.org/​standards/​05rm/​html/​RM-9-6.html#​I3747|Ada.Calendar.Clock]],​ then you're better off using the many nice features of [[http://​adaic.org/​standards/​05rm/​html/​RM-9-6-1.html#​I3773|Ada.Calendar.Formatting]].
  
 =====  The Problem ​ ===== =====  The Problem ​ =====
Line 18: Line 18:
 ===== One Solution ===== ===== One Solution =====
  
-For my experiment I've used the [[http://​libre.adacore.com/​libre/​|GNAT GPL 2010]] compiler, and in this compiler the [[http://​adaic.org/​standards/​05rm/​html/​RM-9-6.html#​I3747|Time]] type is declared as:+In this first solution, we're going to make use of the //'​Address//​ attribute. ​For my experiment I've used the [[http://​libre.adacore.com/​libre/​|GNAT GPL 2010]] compiler, and in this compiler the [[http://​adaic.org/​standards/​05rm/​html/​RM-9-6.html#​I3747|Time]] type is declared as:
  
 <code ada> <code ada>
Line 81: Line 81:
 ===== Another Solution ===== ===== Another Solution =====
  
-The above solution is not the only way to accomplish the goal of outputting the return value of //​Ada.Calendar.Clock//​. There'​s another ​way, better method: Using [[http://​www.adaic.org/​resources/​add_content/​standards/​05rm/​html/​RM-13-9.html|Ada.Unchecked_Conversion]]. Here's how the above //​Time_Image_One//​ function would look if we used //​Ada.Unchecked_Conversion//​ instead:+The above solution is not the only way to accomplish the goal of outputting the return value of //​Ada.Calendar.Clock//​. There'​s another, ​and probably ​bettermethod: Using [[http://​www.adaic.org/​resources/​add_content/​standards/​05rm/​html/​RM-13-9.html|Ada.Unchecked_Conversion]]. Here's how the above //​Time_Image_One//​ function would look if we used //​Ada.Unchecked_Conversion//​ instead:
  
 <code ada> <code ada>
Line 107: Line 107:
   ​   ​
 You're not going to get that with the first method, and in my humble opinion that warning alone makes it worthwhile to use //​Ada.Unchecked_Conversion//​ instead of the //'​Address//​ attribute used in the first solution. You're not going to get that with the first method, and in my humble opinion that warning alone makes it worthwhile to use //​Ada.Unchecked_Conversion//​ instead of the //'​Address//​ attribute used in the first solution.
-===== Full Program =====+===== The Full Program =====
  
 Lets end with a little program that utilizes both solutions to output the value of //​Ada.Calendar.Clock//:​ Lets end with a little program that utilizes both solutions to output the value of //​Ada.Calendar.Clock//:​
Line 120: Line 120:
    use Ada.Strings.Fixed;​    use Ada.Strings.Fixed;​
    use Ada.Text_IO;​    use Ada.Text_IO;​
 +
 +   ​----------------------
 +   ​-- ​ Time_Image_One ​ --
 +   ​----------------------
  
    ​function Time_Image_One    ​function Time_Image_One
Line 134: Line 138:
                    ​Side ​  => Ada.Strings.Left);​                    ​Side ​  => Ada.Strings.Left);​
    end Time_Image_One;​    end Time_Image_One;​
 +   
 +   ​----------------------
 +   ​-- ​ Time_Image_Two ​ --
 +   ​----------------------
        
    ​function Time_Image_Two    ​function Time_Image_Two

Navigation