[m-dev.] pragma foreign_export_enum
Zoltan Somogyi
zoltan.somogyi at runbox.com
Wed Nov 29 17:20:10 AEDT 2017
On Tue, 28 Nov 2017 19:07:12 -0500 (EST), Julien Fischer <jfischer at opturion.com> wrote:
> I suspect any misunderstanding was on my end. The distinction between
> case 1 and case 5 is that because all the fields in the type are uniform
> I should ideally be able to access them in C as an array of uint8_ts
> etc. What I would like here is to be a be to use structured
> representation in Mercury, but be able to pass these same values
> directly to C APIs with minimum (preferably no) intermediate
> transformations.
The Mercury compiler *could* decide to represent f(uint8, uint8, uint8, uint8)
as an array of uints when generating C. It could do that for cells that contain
only fields of the same type, provided these fields have types that directly
correspond to C types. I think that means only {int,uint}{8,16,32,64}
as well as int, uint and float. It *wouldn'* work if the field type was an enum,
even if the enum was bool, because then Mercury's and C's ideas of how
to represent the array would differ.
Note that even in the case of e.g. array of uint8s, the array access operations
would work only for read accesses; any *write* to an array element would
cause chaos, since C code would then update a cell that Mercury thought
was immutable.
Zoltan.
More information about the developers
mailing list