comp.lang.ada
 help / color / mirror / Atom feed
From: husseinp@logica.com (Paul Hussein)
Subject: Re: Ada/Motif problem...
Date: 1996/08/29
Date: 1996-08-29T00:00:00+00:00	[thread overview]
Message-ID: <503hsp$be2@romeo.logica.co.uk> (raw)
In-Reply-To: 1996Aug28.110744.1@eisner


kilgallen@eisner.decus.org (Larry Kilgallen) wrote:


> Dale Stanbrough wrote:
>> 
>> Larry Kilgallen writes:
>> 
>> "Understanding that you have asked us how to lie to an Ada compiler...
>> 
>> > Any inspiration on how to pass Ada strings as callback data in Motif?
>> 
>> Depending on compiler specifics, you may be able to get away with
>> an access to a single character (the first in the string).
>> 
>> Larry Kilgallen"
>> 
>> But that doesn't really help at the other end, that is the routine that
>> gets called and gets passed a pointer to a character. It may know that
>> it points to the first character of a string, but how should it know how
>> long the string is? We lose the bounds of the string if we do this.

>In my experience calling DECwindows from Ada, it wanted a lot of
>null-terminated strings.  Thus the called subsystem, being written
>in C, cannot tell the difference between a pointer to null-terminated
>string and a pointer to the first character thereof.


Spot on! When passing strings from Ada to C one needs to
null-terminate them. The best Idea is to write yourself a little
package the does C conversions and declaraarions much like the ones
that come with DEC Ada or VADS Ada.


package C_Types is

   type Long is ...
   type Int is ...
   type 

   etc
end C_Types; 


package C_Strings is

   type Null_Terminated_String is new STRING;

   type Char_Pointer is new SYSTEM.ADDRESS;
   Null_Char_Pointer : constant Char_Pointer := SYSTEM.NULL_ADDRESS;

   function To_String ( String : in STRING ) return
Null_Terminated_String;
  function To_String ( String : in Null_Terminated_String ) return
Null_Terminated_String;

   etc.
end C_Strings.



   Where what you pass to C would go something like this.


   Null_String              : constant
C_Strings.Null_Terminated_String := C_Strings.To_String ("Hello
Baby");
   String_Pointer : C_Strings.Char_Pointer :=
Null_String'FIRST'ADDRESS;



   Calback ( ......

                  String => String_Pointer
                   .... )


I think this is corrrect.





  reply	other threads:[~1996-08-29  0:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-08-27  0:00 Ada/Motif problem Dale Stanbrough
1996-08-27  0:00 ` Larry Kilgallen
1996-08-27  0:00 ` Dale Stanbrough
1996-08-27  0:00   ` Michael K Rohan
1996-08-28  0:00     ` Larry Kilgallen
1996-08-29  0:00       ` Paul Hussein [this message]
1996-08-28  0:00 ` David C. Hoos, Sr.
1996-08-28  0:00 ` Jon S Anthony
1996-08-29  0:00 ` Jon S Anthony
1996-08-29  0:00   ` Dale Stanbrough
1996-09-02  0:00     ` Sandy McPherson
  -- strict thread matches above, loose matches on Subject: below --
1996-08-28  0:00 G. Vincent Castellano
1996-08-28  0:00 W. Wesley Groleau (Wes)
replies disabled

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