comp.lang.ada
 help / color / mirror / Atom feed
From: nasser@paralysys (Nasser Abbasi)
To: 100331.2264@compuserve.com (R.J. Kirkbride)
Subject: Re: GNAT Strings
Date: 1996/04/21
Date: 1996-04-21T00:00:00+00:00	[thread overview]
Message-ID: <nh20lif3u4.fsf@paralysys> (raw)
In-Reply-To: 4l0oiq$4e8@arl-news-svc-2.compuserve.com

In article <4l0oiq$4e8@arl-news-svc-2.compuserve.com> 100331.2264@compuserve.com (R.J. Kirkbride) writes:


   Does anyone know how strings are stored in GNAT,
   and thus how they can be sent from C.

   I think a pointer is first sent to the string and then
   a pointer to a structure containing first and last pointers
   but I am not absolutely sure this is correct.

   Any help would be much appreciated,

   Rob.

for unbounded string is, a-strunb.ads shows it is a pointer, 
opps, I mean access to a string:
 
>private
>   package AF renames Ada.Finalization;
>
>   type Unbounded_String is new AF.Controlled with record
>      Reference : String_Access;
>   end record;

for bounded string , a-strbou.ads shows it is a record
with length field, and the data itself field, where length
indicates current length: 

>   private
>
>      type Bounded_String is record
>         Length : Length_Range := 0;
>         Data   : String (1 .. Max_Length);
>      end record;


The length of unbounded string is then found like this:

from a-strunb.adb:

   function Length (Source : Unbounded_String) return Natural is
   begin
      return Source.Reference.all'Length;
   end Length;


The length of the bounded string is in the record itself shown above.
so from a-strbou.adb:

      function Length (Source : in Bounded_String) return Length_Range is
      begin
         return Source.Length;
      end Length;


String itself offcourse is array of characters.

to interface to C, there is a package for that (interfaces package)
one of its children is C.Interface .

Nasser




      parent reply	other threads:[~1996-04-21  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-16  0:00 GNAT Strings R.J. Kirkbride
1996-04-16  0:00 ` Robert Dewar
1996-04-18  0:00 ` steved
1996-04-21  0:00 ` Nasser Abbasi [this message]
replies disabled

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