subtype - Equivalence of Array types in Ada -
while trying make ada binding third party c/c++ library (sapnwrfcsdk) came problems of type inference array types:
first problem:
the gnat-binding-generator gcc (gcc -fdump-ada-spec) generating lots of intermediate named array types different index ranges:
type anon3115_anon3128_array array (0 .. 8) of aliased sap_uc; type anon3115_anon3131_array array (0 .. 3) of aliased sap_uc; type anon3115_anon3134_array array (0 .. 12) of aliased sap_uc;
those types used in records. if want pass fields procedure or function have unbounded type signature example following type:
type sap_uc_array array (int range <>) of aliased sap_uc;
but generated types no subtypes of cannot passed. 1 solution change field declarations in records to:
field : sap_uc_array(0 .. 8);
but mean "process" generated binding file , change definitions. possible create named array subtype specified index range or solution?
second problem:
some array type definitions have equivalent component types.
subtype rfc_char sap_uc; type rfc_date array (0 .. 7) of aliased rfc_char;
this array definition not considered equivalent array of component type sap_uc. possible tell ada these types equivalent?
you can in ada:
type sap_uc_array array (int range <>) of aliased sap_uc; subtype anon3115_anon3128_array sap_uc_array (0 .. 8); subtype anon3115_anon3131_array sap_uc_array (0 .. 3); subtype anon3115_anon3134_array sap_uc_array (0 .. 12);
i apologize if knew this, can't tell whether question getting gnat-binding-generator generate subtype
declarations. can't gnat question.
as second question: every type
declaration creates new, distinct type; there no way treat 2 distinct types equivalent. (the language automatically convert types in cases, think that's in cases involving anonymous types or special types defined language such "universal integer".) in case, though, there's no particular reason declare array type rfc_date
. if have type that's array of sap_uc
, such sap_uc_array
, say
subtype rfc_date sap_uc_array (0 .. 7);
since element type, rfc_char, "rename" of sap_uc. (of course won't if type declarations being generated tool.)
Comments
Post a Comment