comp.lang.ada
 help / color / mirror / Atom feed
* Interfacing enums with C
@ 2014-08-17 19:02 Victor Porton
  2014-08-17 19:39 ` Simon Wright
  0 siblings, 1 reply; 7+ messages in thread
From: Victor Porton @ 2014-08-17 19:02 UTC (permalink / raw)


Let in C code are defined:

typedef enum { A=1, B=2 } option_type;

void f(option_type option);

Let we also have

type Option_Type is (A, B);
for Option_Type'Size use Interfaces.C.unsigned'Size;
for Option_Type use (A=>1, B=>2);

X: Option_Type := A;

Which of the following code is correct (accordingly RM)?

-- First code
declare
   procedure F (Option: Option_Type)
      with Import, Convention=>C, External_Name=>"f";
begin
   F(X);
end;

or

-- Second code
declare
   procedure F (Option: Interfaces.C.unsigned)
      with Import, Convention=>C, External_Name=>"f";
   function Conv is new Ada.Unchecked_Conversion(Option_Type, Interfaces.C.unsigned);
begin
   F(Conv(X));
end;

I think both first and second Ada fragments are correct but am not sure.

-- 
Victor Porton - http://portonvictor.org


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-08-18  9:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-17 19:02 Interfacing enums with C Victor Porton
2014-08-17 19:39 ` Simon Wright
2014-08-17 19:46   ` Victor Porton
2014-08-17 19:48     ` Victor Porton
2014-08-17 22:48       ` Peter Chapin
2014-08-18  9:19         ` Simon Wright
2014-08-18  9:17     ` Simon Wright

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox