English 中文(简体)
Pass a Boolean Ada type in Interfaces.C
原标题:

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 Interfaces.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;




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签