comp.lang.ada
 help / color / mirror / Atom feed
* C interface using a record with discriminant and representation clauses
@ 2009-06-30 23:01 Hibou57 (Yannick Duchêne)
  2009-06-30 23:38 ` Hibou57 (Yannick Duchêne)
  0 siblings, 1 reply; 3+ messages in thread
From: Hibou57 (Yannick Duchêne) @ 2009-06-30 23:01 UTC (permalink / 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 ? **




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

end of thread, other threads:[~2009-07-05  3:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-30 23:01 C interface using a record with discriminant and representation clauses Hibou57 (Yannick Duchêne)
2009-06-30 23:38 ` Hibou57 (Yannick Duchêne)
2009-07-05  3:17   ` Hibou57 (Yannick Duchêne)

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