* C->Ada: Converting char* to unsigned long
@ 1996-05-16 0:00 Chris Jones
1996-05-16 0:00 ` Pascal Ledru
0 siblings, 1 reply; 2+ messages in thread
From: Chris Jones @ 1996-05-16 0:00 UTC (permalink / raw)
Cc: cbj1329
How can I convert the following to ada:
bcopy( (char*)pHost_Info->h_addr,
(char*)&Serv_Addr.sin_addr,
pHost_Info->h_length );
where:
-- pHost_Info->h_addr is a char* to a string with length h_length,
-- Serv_Addr.sin_addr is an unsigned long
I have tried Unchecked_Conversion, but it does not work for the
unconstrained type Interfaces.C.Char_Array.
A function which does a straight byte copy without regard to type
would be helpful, I guess...
thanks in advance.
chris jones.
cbj1329@is2.nyu.edu
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: C->Ada: Converting char* to unsigned long
1996-05-16 0:00 C->Ada: Converting char* to unsigned long Chris Jones
@ 1996-05-16 0:00 ` Pascal Ledru
0 siblings, 0 replies; 2+ messages in thread
From: Pascal Ledru @ 1996-05-16 0:00 UTC (permalink / raw)
As you noticed the problem comes from the fact that you cannot
instantiate Unchecked_Conversion (or any generic) with an
unconstrained type.
There is probably a simpler solution but the following will work:
with Text_IO;
with Interfaces.C.Strings;
use Interfaces.C.Strings;
procedure convert is
package Integer_IO is new Text_IO.Integer_IO(Integer);
C : chars_ptr;
I : Integer;
subtype Short_String is String(1..4);
S : String(1..4);
function To_Integer is new Unchecked_Conversion
( Source => Short_String,
Target => Integer );
begin
C := New_String( Str => "AAAA" & ASCII.NUL ); -- char*
S := Value( Item => C);
Integer_IO.Put( Item => To_Integer(S), Base => 16 );
Text_IO.New_Line;
end;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1996-05-16 0:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-05-16 0:00 C->Ada: Converting char* to unsigned long Chris Jones
1996-05-16 0:00 ` Pascal Ledru
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox