caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* C interface and representation
@ 1998-10-26 14:25 Don Syme
  0 siblings, 0 replies; only message in thread
From: Don Syme @ 1998-10-26 14:25 UTC (permalink / raw)
  To: caml-list


I think we'd all agree that the O'Caml-C interface reveals rather a lot 
about the runtime layout of various O'Caml types.  For example,
it reveals that record types are represented as tuples.  

I'm wondering if the O'Caml compiler could emit a set of C macros that
effectively hides these representation choices.  For example,
for a file foo.ml

  type abc = { flag1 : bool; flag2: bool; flag3: bool }

ocamlc {some option} foo.ml > foo.h

could generate C macros like
#define Foo__abc__flag1(value) ...
#define Foo__abc__flag2(value) ...
#define Foo__abc__flag3(value) ...

(where each of these are lvalues)

This would, of course, make C code that creates and manipulates
record valuables more robust, since it would be independent of the
record ordering.  I have a current application that creates record
values with 10-20 fields (many of them boolean flags), and it is
just silly to hardwire field numbers.  Such records will probably
be common in any interface to substantial APIs (I have in mind various
Microsoft APIs).

It may also be plausible for the compiler team to optimize the layout of
records such as the one above at a later date.  Any self respecting 
C programmer would expect the above record to consume 1 byte, and it would
be nice to at least allow for the possibility of such optimizations,
wouldn't it, without breaking C code?  (Or, alternatively, to allow
for a richer type representation description language that, for example,
specified field widths)

[ Actually, I've glossed over the fact that bits are not lvalues
in C, so both "set" and "get" macros may be required.  Also, marshalling
and so on would be affected by such optimizations, but that's another story.
]

Cheers,
Don




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1998-10-27 19:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-10-26 14:25 C interface and representation Don Syme

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).