I would like to now how to pass a standard Boolean Type in Ada through the Interfaces.C package in order to call a DLL function. The Interface开发者_JAVA百科s.C package does not contain the Ada Boolean type since the boolean type does not exist in ANSI C. I have a DLL function written in C++ whose exported function prototype has an argument of type Bool. How is this passed in the Intefaces.C package in order to call the DLL exported function?
traditionally, in C, a boolean is represented with an int
type. in C++, a bool
type is defined, but note the lowercase 'b'. if your argument is of type Bool
(note the uppercase 'B') then you should have a class declaration somewhere (in your C++ library) which will tell you more about the implementation of the type. generally, such a Bool class is made compatible with a standard bool type through some artifact of the language: the Bool class defines no virtual function and keeps its value in a member judiciously placed first in the definition of the class.
i did not test it, but i would say you can go with an int
type. make a test to be sure it is accepted by the C++ function. for converting from Boolean to int
, you may use something like Interfaces.C.int(Boolean'Pos(your_bool_value))
.
also note that, as specified in the Ada Reference Manual [B.3.62]: An implementation may provide additional declarations in the C interface packages.
so check your implementation of Interfaces.C
, it may contain a definition for a bool
type.
type Boolean_2_Int is (Bool : Boolean := False) is
record
I : Interfaces.C.Unsigned_Long := 0;
case Bool is
when True =>
I := 1;
when False =>
I := 0;
end case;
end record;
精彩评论