comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <sb463ba@d2-hrz.uni-duisburg.de>
Subject: Re: conversion
Date: Sun, 6 Jul 2003 20:04:13 +0000 (UTC)
Date: 2003-07-06T20:04:13+00:00	[thread overview]
Message-ID: <be9vbt$gej$1@a1-hrz.uni-duisburg.de> (raw)
In-Reply-To: e2e5731a.0307050906.227e945f@posting.google.com

Alexander Kopilovitch <aek@vib.usr.pu.ru> wrote:
: Georg Bauhaus wrote:
: 
:> > The varying strings of unspecified maximum size are common for many applications
:> > outside of current, quite restricted Ada world. And arrays of such strings
:> > are no less common.
:>
:>Care to list some examples?
: 
:  /* C/C++ example */
: 
:  char *Titles[] = {
:                    "Quizionary",
:                    "Nose To Nose",
:                    "Myself",
:                    "General Dissent",
:                    "Veteran's Opinion",
:                    "Corporate Science Weekly",
:                    "Truth, Wealth, Health",
:                    "Bribery Times"
:                   };

If you need to have syntactic sugar, you can have

   Titles: constant array(1..8) of String_Access :=
     (-"Quizionary",
      -"Nose To Nose",
      -"Myself",
      -"General Dissent",
      -"Veteran's Opinion",
      -"Corporate Science Weekly",
      -"Truth, Wealth, Health",
      -"Bribery Times");

where
   function "-"(s: String) return String_Access;

I am always trying something like the following. The string literals end
up as literals in the assembly listing, so there does not seem to
be allocation at run time, despite new:

procedure str is

   type String_Access is access constant String;

   Titles: constant array(1..8) of String_Access :=
     (new String'("Quizionary"),
      new String'("Nose To Nose"),
      new String'("Myself"),
      new String'("General Dissent"),
      new String'("Veteran's Opinion"),
      new String'("Corporate Science Weekly"),
      new String'("Truth, Wealth, Health"),
      new String'("Bribery Times"));

begin
   null;
end str;

But, as a sidenote, I alway try to avoid string literals in source
code. They make the text fixed, a typo requires recompilation,
language translation requires that programmers be involved, because
the translators do not know how to recompile the program to include
the latest translations, etc. If that seems too much, there could be
an enumeration of the 8 strings above, such that, for every natural
language (or other variation in the string values), you could have

    array(Languages, Kinds_of_Titles) of String_Access := ...;

in some library package.

What is more, the varying size you have mentioned is known at
compile time in your example. But for sure string literals are not
the usual input to a string processing program?

-- Georg



  parent reply	other threads:[~2003-07-06 20:04 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-27 10:51 conversion Andrew
2003-06-27 12:22 ` conversion Dmitry A. Kazakov
2003-06-27 12:37 ` conversion Stephen Leake
2003-06-27 14:26   ` conversion Bill Findlay
2003-06-27 17:04     ` conversion Georg Bauhaus
2003-07-04  0:21     ` conversion Dave Thompson
2003-06-27 13:25 ` conversion Robert I. Eachus
2003-06-27 18:42   ` conversion tmoran
2003-06-27 14:49 ` conversion Matthew Heaney
2003-06-27 17:10 ` conversion Georg Bauhaus
2003-06-27 17:13 ` conversion Alexander Kopilovitch
2003-06-27 17:34   ` conversion Preben Randhol
2003-06-27 22:10     ` conversion Alexander Kopilovitch
2003-06-28  9:46       ` conversion Preben Randhol
2003-06-27 22:13   ` conversion Robert I. Eachus
2003-06-30  8:52     ` conversion Dmitry A. Kazakov
2003-07-03  7:03       ` conversion Robert I. Eachus
2003-07-09  7:42         ` conversion Dmitry A. Kazakov
2003-07-09 17:04           ` conversion Robert I. Eachus
2003-07-10 10:19             ` conversion Dmitry A. Kazakov
2003-07-11  1:56               ` conversion Alexander Kopilovitch
2003-07-05  2:40     ` conversion Alexander Kopilovitch
2003-07-05  6:33       ` conversion Georg Bauhaus
2003-07-05 17:06         ` conversion Alexander Kopilovitch
2003-07-06  3:53           ` conversion Robert I. Eachus
2003-07-06  5:13             ` conversion Jeffrey Carter
2003-07-06 12:45               ` conversion Chad R. Meiners
2003-07-07  1:09             ` conversion Alexander Kopilovitch
2003-07-06 20:04           ` Georg Bauhaus [this message]
2003-07-07 14:55             ` conversion Stephen Leake
2003-07-07 21:36               ` conversion Alexander Kopilovitch
     [not found] <002701c33e22$8e9deaf0$0201a8c0@win>
2003-06-29 20:15 ` conversion David C. Hoos, Sr.
  -- strict thread matches above, loose matches on Subject: below --
2003-06-29  9:41 conversion Andrew
2003-07-04 10:42 ` conversion Janeit
2003-06-28  8:46 conversion Andrew
2003-06-28  9:49 ` conversion Preben Randhol
2003-06-30 14:08 ` conversion Stephen Leake
2003-06-27 17:37 conversion Andrew
2003-06-27 17:32 ` conversion Stephen Leake
2003-06-28  2:55 ` conversion Jeffrey Carter
1998-07-22  0:00 conversion Rick
1998-07-22  0:00 ` conversion Corey Ashford
1998-07-22  0:00   ` conversion Corey Ashford
1998-07-22  0:00 ` conversion Richard Toy
replies disabled

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