[Openmcl-devel] slet/rlet with C functions?

Gary Byers gb at clozure.com
Thu Aug 17 15:35:40 PDT 2006

A C (or ObjC) function that returns a structure does so by
  a( accepting a pointer to an instance of such a structure as a hidden
     first argument
  b) filling in the values of that first argument's fields
  c) returning no meaningful conventional value, i.e., behaving like
     something declared to return "void".

If there were a function that "created" a CGRect from 4 floats, it might
be prototyped something like:

CGRect MakeCGRect(float x, float y, float width, float height);

but it's actually implemted as if it were:

void MakeCGRect(CGRect *result, float x, float y, float width, float height)
   result.origin.x = x;
   result.origin.y = y;
   result.size.width = width;
   result.size.height = height;

I'm pretty sure that the interface translator recognizes struture-returning
functions and adds the invisible argument (the "return" pointer) to the
foreign function's argument list, so that your example could be:

(ccl::slet ((r (ccl::ns-make-rect 0.0 0.0 100.0 100.0)))
   (rlet ((r2 :<NSRect))
     (#_CGRectIntegral r2 r)))  ; r2/result passed as 1st arg

(SLET ((var form)) ...)

does this for you and hides some of that ugliness, but it only works
when it can tell that each "form" is a foreign function call that
nominally returns a structure.  It can tell that for ObjC message sends
and for a few built-in magic constructors; I'm not sure how easy/hard
it would be to generalize.

On Thu, 17 Aug 2006, Phil wrote:

> I'm trying to figure out how to use slet/rlet with a C function call
> such as:
> (ccl::slet* ((r (ccl::ns-make-rect 0.0 0.0 100.0 100.0))
> 		   (r2 (#_CGRectIntegral r))))
> but of course slet doesn't know how to deal with #_CGRectIntegral and
> I haven't had any better luck with rlet, so... is there currently a
> comparable way of dealing with structures defined via the interface
> files and C functions?
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel

More information about the Openmcl-devel mailing list