comp.lang.ada
 help / color / mirror / Atom feed
* how to get aliased string pointer
@ 2001-07-12 11:55 Maxim Reznik
  2001-07-12 17:19 ` Jeffrey Carter
  0 siblings, 1 reply; 3+ messages in thread
From: Maxim Reznik @ 2001-07-12 11:55 UTC (permalink / raw)


Hello CLA,

Compiling following programm in GNAT3.13p I get error

aaa.adb:16:10: object subtype must statically match designated subtype

procedure aaa is

   type Shared_String (Length : Natural) is record
       Count : Natural := 1;
       Space : aliased String (1 .. Length);
       pragma Atomic (Count);
   end record;


   type String_Access is access all String;

   p: String_Access;
   str: Shared_String(10);

begin
   p:=str.Space'Access;
end;

Actually I would like to have a function that returns String_Access
pointed to string located in an Shared_String object.

   function Get_String (U  : Shared_String_Access) return String_Access is
   begin
      return U.Space'Access;
   end;

Is there any way to make such function?

As far as I understand I unable to convert constrained
subtype to unconstrained.


--
Maxim Reznik






^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how to get aliased string pointer
  2001-07-12 11:55 how to get aliased string pointer Maxim Reznik
@ 2001-07-12 17:19 ` Jeffrey Carter
  2001-07-13  7:19   ` Maxim Reznik
  0 siblings, 1 reply; 3+ messages in thread
From: Jeffrey Carter @ 2001-07-12 17:19 UTC (permalink / raw)


The real question is what you are trying to acheive by this. The use of
access types is rarely needed in well designed Ada, and over use of
access values is a common sign of writing Ada with the C mind set, since
in C practically everything has to be a pointer. If you can tell us what
you need to do at the problem level, we can probably help you achieve it
Ada, probably without access values.

-- 
Jeffrey Carter



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how to get aliased string pointer
  2001-07-12 17:19 ` Jeffrey Carter
@ 2001-07-13  7:19   ` Maxim Reznik
  0 siblings, 0 replies; 3+ messages in thread
From: Maxim Reznik @ 2001-07-13  7:19 UTC (permalink / raw)



"Jeffrey Carter" <jeffrey.carter@boeing.com> wrote in message news:3B4DDC16.9A98559B@boeing.com...
> The real question is what you are trying to acheive by this. The use of
> access types is rarely needed in well designed Ada, and over use of
> access values is a common sign of writing Ada with the C mind set, since
> in C practically everything has to be a pointer. If you can tell us what
> you need to do at the problem level, we can probably help you achieve it
> Ada, probably without access values.
>
> --
> Jeffrey Carter
Actualy the question is theoretical one.
Is it possible to convert access to constrained array to unconstrained access type?

A couple weeks ago I tried to make more efficient impementation of Unbounded_String.
I posted message to CLA and was pointed to lack of task synchronization.
I introduced protected object to fix it. Trying to use new Unbounded_String I encountered
child unit Ada.Strings.Unbounded.Aux. The point is that using
function To_String(Unbounded_String) return String is an unefficient way to access String.
People of  ACT made a hole (function Get_String (U  : Unbounded_String) return String_Access) to
lighten access. Here is their comments

--  This child package of Ada.Strings.Unbounded provides some specialized
--  access functions which are intended to allow more efficient use of the
--  facilities of Ada.Strings.Unbounded, particularly by other layered
--  utilities (such as GNAT.Patterns).

So I'm playing with pointer to emulate GNAT behavior.
(Is this enough well designed?)

I thouth it's easy to impement such function returning acess to aliased
component of my record type Shared_String. But it seems the component
has constrained type and I cant convert pointer to it to unconstrained access type.


--
Maxim Reznik








^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-07-13  7:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-12 11:55 how to get aliased string pointer Maxim Reznik
2001-07-12 17:19 ` Jeffrey Carter
2001-07-13  7:19   ` Maxim Reznik

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