I am running an experiment in trying to link google test to ada95 for unit testing. I know ada has aunit and ahven, but this is just to see if this is possible and is outside of the scope of my question. I have successfully been able to do simple functions and procedures with the basic data types. The next thing I would like to try to do is similar to the following:
Here is the main.cpp file:
#include <stdio.h>
#include <gtest/gtest.h>
extern "C" {
int firstElement(int buffer[]);
}
TEST(tryTest, checkBuffer){
int buffer[10] = {10,1,6,4,3,2,1,3,4,6};
ASSERT_EQ(buffer[0],firstElement(buffer));
}
int main(int argc, char ** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
for simplicity I will just put the ads file:
Lib_test.ads
with Interfaces.C;
with Interfaces.C.Pointers;
package Lib_Test is
function FirstElement(a: Interfaces.C.Pointers) return Interfaces.C.Int;
pragma Export(C,FirstElement,"firstElement");
end Lib_Test;
I know in c you are passing in the pointer to the first element not the entire array for the function. That is why I tried to use Interfaces.C.Pointers for the data type but I got the following error
subtype mark required in this context
found "Pointers" declared at i-cpoint.ads:44
I have not found a good example of using other array types besides char arrays. Can someone show me how I can use Interfaces.C.Pointers for an integer array or even how I can fix this, I believe it is just my data type in the parameter of the function. I want to be able to access the c integer array in the ada function.
Thank you all!
Interfaces.C.Pointers
is a generic package, not a subtype.If you don't understand the difference, then you really don't understand Ada well enough yet to be interfacing to foreign languages. Concentrate on learning the basics of the language first. – UnitePositive
?) – Tryma