comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Accessing Addresses in a Passed String
Date: Sat, 1 Jan 2022 20:23:40 +0100	[thread overview]
Message-ID: <sqq9nq$1osl$1@gioia.aioe.org> (raw)
In-Reply-To: ea4fff71-c53e-4416-a345-2df277f78d0fn@googlegroups.com

On 2022-01-01 19:53, Pat Van Canada wrote:
  > in the declarative section, I can write:
> 
>         str2 : aliased string( 1 .. 4 ) ;
> 
> and then I could potentially access the address of each character in the string.
> 
> However, I cannot use "aliased" in an argument list and worse yet, since it is effectively a character array, it will be passed by pointer.

You probably mean "by reference." It is not clear why do you care.

> Here is a little snippet of what I am trying to do:
> 
>         procedure  double_draw (  row : in integer ;
>                                column : in integer ;
>                                  word : in out string ) is
> 
>         begin
> 
>         for j in  column .. word'length loop
>         input_pad(row,j).ch_ptr             := word(j)'access ;

Looks like an attempt to produce a dangling pointer in Ada. Not an easy 
task.

You certainly should never ever assign pointers to actual parameters 
unless you communicating with C.

> This is not going to work, does anyone have a suggestion of how I might work around this? My only solution right now is to move this to the calling code and simply pass the address of each character of a string

You should describe the actual problem not a [wrong] solution to it. If 
you want to reference inside a string you must declare a helper type.

Typically one uses some reference counting handle to the string body and 
indices to the beginning and end of the slice. Though an access type 
would do as well, just unsafe.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  reply	other threads:[~2022-01-01 19:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-01 18:53 Accessing Addresses in a Passed String Pat Van Canada
2022-01-01 19:23 ` Dmitry A. Kazakov [this message]
2022-01-01 19:40   ` Pat Van Canada
2022-01-01 20:16     ` Dmitry A. Kazakov
2022-01-01 23:03       ` Pat Van Canada
2022-01-01 20:57 ` Niklas Holsti
2022-01-01 23:37   ` Pat Van Canada
2022-01-02 13:15   ` Pat Van Canada
2022-01-02 14:41   ` Pat Van Canada
replies disabled

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