comp.lang.ada
 help / color / mirror / Atom feed
* GNAT Strings
@ 1996-04-16  0:00 R.J. Kirkbride
  1996-04-16  0:00 ` Robert Dewar
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: R.J. Kirkbride @ 1996-04-16  0:00 UTC (permalink / raw)


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.





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

* Re: GNAT Strings
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1996-04-16  0:00 UTC (permalink / raw)


Rob said

"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,"

You should not write C at this level. Instead to pass strings across
the Ada-C interface, use the protable routines defined in and under
Interfaces.C.





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

* Re: GNAT Strings
  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
  2 siblings, 0 replies; 4+ messages in thread
From: steved @ 1996-04-18  0:00 UTC (permalink / raw)


In <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.
>
Look to the package "Interfaces.c" in the file i-c.ads and you will find a
function:

     function To_Ada
     (Item     : in char_array;
      Trim_Nul : in Boolean := True)
      return     String;

This is probably the ticket you're looking for.





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

* Re: GNAT Strings
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Nasser Abbasi @ 1996-04-21  0:00 UTC (permalink / raw)
  To: R.J. Kirkbride

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




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

end of thread, other threads:[~1996-04-21  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox