comp.lang.ada
 help / color / mirror / Atom feed
From: rieachus@comcast.net
Subject: Re: Substrings as argument to procedures/functions
Date: Mon, 25 Apr 2016 08:33:18 -0700 (PDT)
Date: 2016-04-25T08:33:18-07:00	[thread overview]
Message-ID: <518c7059-14c6-4344-a251-129cca2621af@googlegroups.com> (raw)
In-Reply-To: <nemdnn$4lc$1@loke.gir.dk>

On Wednesday, April 13, 2016 at 5:29:29 PM UTC-4, Randy Brukardt wrote:

> Probably a better example is to remember that the range of Positive is 
> implementation-defined, and that the language only requires the upper bound 
> to be at least 32767. So if you need strings that have potentially more 
> characters than that (to read an entire text file, for instance), and you 
> want the code to be unconditionally portable (to steal someone else's line), 
> you need to declare a type yourself (here, assuming that a million 
> characters are enough)...

Is it time to "fix" this?  Or are there still Ada compilers around that use 16-bit String indexes by default? I remember when (in the early days of Ada83) the question of whether String should use 16 or 32 bit indexes was a major implementation decision.  Today, compilers that support hardware indexes shorter than 32-bits are probably mapping to some hardware defined offset field in instructions. Using such indexes when the subtype allows is obviously an optimization worth supporting.  But in Ada defining "subtype Short_String is String range (1..32767);" or whatever allows using such a hardware type if available.  But there is no need to make Short_String a type.

Yes, programs may have records with character string fields limited such that the index can fit into a 16-bit field in the record.  But I can't imagine doing that without an explicit layout for the record or at least a size for the index field. Back to the original topic here, you want/need sliding to work such that

    type Rec is
      Name_Length : Integer range 0..32_767; 
      Name: String;
    end;
    for Rec use ...
    ...
    Name_Length := Param'Length;
    Name(1..Name_Length) := Param;

 works as expected.

  reply	other threads:[~2016-04-25 15:33 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-12  8:25 Substrings as argument to procedures/functions reinkor
2016-04-12  9:01 ` Dmitry A. Kazakov
2016-04-12 16:55   ` reinkor
2016-04-12 18:37     ` Dmitry A. Kazakov
2016-04-13  4:44       ` reinkor
2016-04-13  7:19         ` Dmitry A. Kazakov
2016-04-13 10:16         ` Brian Drummond
2016-04-13 11:43           ` reinkor
2016-04-13 11:54             ` Pascal Obry
2016-04-13 12:30               ` Mart van de Wege
2016-04-13 12:47                 ` Egil H H
2016-04-13 13:19                   ` Mart van de Wege
2016-04-13 16:57                 ` Jeffrey R. Carter
2016-04-12 18:17 ` Robert A Duff
2016-04-12 18:34 ` Jeffrey R. Carter
2016-04-13 21:29   ` Randy Brukardt
2016-04-25 15:33     ` rieachus [this message]
2016-04-25 22:07       ` Randy Brukardt
2016-04-26  6:12         ` Georg Bauhaus
2016-04-26 18:41           ` Randy Brukardt
2016-04-13 11:22 ` G.B.
replies disabled

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