From: Victor Porton <porton@narod.ru>
Subject: Interfacing enums with C
Date: Sun, 17 Aug 2014 22:02:45 +0300
Date: 2014-08-17T22:02:45+03:00 [thread overview]
Message-ID: <lsqu8i$uco$1@speranza.aioe.org> (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
next reply other threads:[~2014-08-17 19:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-17 19:02 Victor Porton [this message]
2014-08-17 19:39 ` Interfacing enums with C 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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox