From: "Hibou57 (Yannick Duchêne)" <yannick_duchene@yahoo.fr>
Subject: C interface using a record with discriminant and representation clauses
Date: Tue, 30 Jun 2009 16:01:53 -0700 (PDT)
Date: 2009-06-30T16:01:53-07:00 [thread overview]
Message-ID: <eadaed8a-0c42-4fa0-b2ff-1c55eaf7b3a6@b9g2000yqm.googlegroups.com> (raw)
Hello,
I wonder about what to think about it, while I could not imagine a
better solution :
Say a C structure is to be interfaced with Ada. The structure has a
"count" member and a variable length array, commonly defined in C as
something like elements[1].
I.e. a C structure like
typedef struct {
int count;
my_element_type elements[1];
} my_struct;
I'm tempted to use something like
type Element_Type is <Something>;
for Element_Type'Size use <Something>;
type Array_Type is array (Index_Type range <>) of aliased
Element_Type;
pragma Convention (C, Entity => Array_Type);
type Record_Type (Length : Index_Type) is record
Elements : Array_Type (1..Length);
end record;
for Record_Type use record
Length at 0 range 0 .. Something; -- Tell the Ada compiler where
the C
-- compiler has
placed the “ discriminant ”
end record;
pragma Convention (C, Entity => Record_Type);
Though the trouble may be that it is not possible to specify the bits
address of Elements, beceause it is not possible to have something
like “ Elements at 0 range <Something> .. <Something> * Length - 1; ”
What to think about it ?
Is it portable through most compilers ?
** Is it trustable ? **
next reply other threads:[~2009-06-30 23:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-30 23:01 Hibou57 (Yannick Duchêne) [this message]
2009-06-30 23:38 ` C interface using a record with discriminant and representation clauses Hibou57 (Yannick Duchêne)
2009-07-05 3:17 ` Hibou57 (Yannick Duchêne)
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox