Reputation: 433
I'm trying to write a version of my C program in Ada. My C function call looks like this:
void convert(const void* in, void* out){
MyType* convertedIn = (MyType*)in;
MyType* convertedOut = (MyType*)out;
//Assignments and operations to translate values across
//Example
convertedOut->meters = convertedIn->feet * 0.3048;
}
After searching, I was unable to find anything out there about type casting or any form of Object class or void pointer object for Ada. How would I implement a function like this in Ada?
If I can't implement the function in Ada, how would I wrap the c function with Ada?
I'm using Ada95
Upvotes: 1
Views: 1538
Reputation: 433
I managed to get what I needed using System.Address and Ada.Unchecked_Conversion. Below is my code:
with MyPackage;
type MyTypePtr is access MyType;
procedure Convert (From : in System.Address;
To : out System.Address) is
function ConvertAddressToMyType is new Ada.Unchecked_Conversion(
Source => System.Address;
Target => MyTypePtr);
begin
null; -- Implement conversion here
end Convert;
Upvotes: 0
Reputation: 6611
type Example is tagged null record;
procedure Convert (From : in Example'Class;
To : out Example'Class) is
begin
null; -- Implement conversion here
end Convert;
Upvotes: 2