comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@on2.com (Matthew Heaney)
Subject: Re: Array Of Constant Strings?
Date: 15 Apr 2003 19:17:14 -0700
Date: 2003-04-16T02:17:15+00:00	[thread overview]
Message-ID: <1ec946d1.0304151817.7182ecd8@posting.google.com> (raw)
In-Reply-To: b7h7i3$op4$1@a1-hrz.uni-duisburg.de

Georg Bauhaus <sb463ba@d2-hrz.uni-duisburg.de> wrote in message news:<b7h7i3$op4$1@a1-hrz.uni-duisburg.de>...
> 
> Will you collect a few impressions students have of the
> readability of Ada programs? (As this might add more substance to
> the argument that Ada syntax has advantages.)

Well, here's one case where the C syntax is much simpler.  In order to
declare an array of strings in C, all I have to do is:

  const char* sa[] =
  {
     "now",
     "is",
     "the",
     "time"
  };

To do the equivalent in Ada, I'd have to do this:

  type String_Constant_Access is
     access constant String;

  type String_Array is
     array (Positive range <>) of String_Constant_Access;

  Now_String : aliased constant String := "now";
  Is_String : aliased constant String := "is";
  The_String : aliased constant String := "the";
  Time_String : aliased constant String := "time";
  
  SA : constant String_Array :=
    (Now_String'Access,
     Is_String'Access,
     The_String'Access,
     Time_String'Access);

Tucker showed this on CLA once:

   SA : constant String_Array := 
     (new String'("now"),
      new String'("is"),
      new String'("the"),
      new String'("time"));

Since all the string literals have static values, then no heap is
really allocated.  But this is really a compiler optimization -- I
don't know whether you can really depend on it.



  reply	other threads:[~2003-04-16  2:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-14  2:58 Array Of Constant Strings? Dr Nancy's Sweetie
2003-02-14  4:28 ` tmoran
2003-02-14  7:28 ` Dale Stanbrough
2003-02-14  7:47   ` tmoran
2003-02-14 10:06     ` Dale Stanbrough
     [not found] ` <19guh-2f4.ln1@beastie.ix.netcom.com>
2003-02-14 19:41   ` Jeffrey Carter
2003-02-14 20:38     ` tmoran
     [not found]     ` <e0q0i-n14.ln1@beastie.ix.netcom.com>
2003-02-15 22:28       ` Jeffrey Carter
2003-02-22 19:31     ` Robert A Duff
2003-04-14 18:43       ` Dr Nancy's Sweetie
2003-04-15 11:36         ` Georg Bauhaus
2003-04-15 13:40           ` Dr Nancy's Sweetie
2003-04-15 15:13             ` Georg Bauhaus
2003-04-16  2:17               ` Matthew Heaney [this message]
2003-04-16 16:35                 ` Chad R. Meiners
2003-04-16 21:03                 ` Georg Bauhaus
2003-04-17 17:53                   ` Robert A Duff
2003-04-17 20:34                     ` Georg Bauhaus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox