[Openmcl-devel] Accessing foreign #define'd constants

rm at fabula.de rm at fabula.de
Wed Dec 22 12:43:46 PST 2004


On Wed, Dec 22, 2004 at 03:32:31PM -0500, David Steuber wrote:
> On Dec 22, 2004, at 12:46 PM, Denis Bueno wrote:
> 
> >The problem was that what I had assumed was a C constant was actually 
> >a #define'd C macro ... so of course I couldn't call it.
> 
> Right.  #define is simply a text substitution.  I don't know if I am 
> comfortable calling them C macros ;-)

Well, there are people out there calling M4 macros :-)

> >I know it's not the responsibility of the openmcl documentation to 
> >teach people C, but, maybe a little note (in sec. 9.8?) about the 
> >preferred way to have openmcl call C macros (like by making "glue" via 
> >a my_macro_call.c file with a my_macro_call() function and calling 
> >that function from openmcl, 

That doesn't really work. The interface files (those with the .ffi suffix)
are generated by a patched version of the gcc compiler after (!) the 
headers have been preprocessed with the cpp preprocessor - gcc doesn't
even "see" the #defines. Yes, it's nasty - i got bitten by it too. Some
smarty just changed the gtk signal connect function into a macro ...


> or something) would be helpful to anyone 
> >who runs into this problem in the future. I'm certainly willing to 
> >write it, if that is acceptable.


> The Carbon headers make a lot of use of enums for C constants.  These 
> have the advantage of being real constants that are also available via 
> #$.  What I hate though is the frequent practice of enums that are 
> assigned like this:
> 
> foo = 'ctrl',
> 
> Joy!  At least #$ works.  When the same thing is a #define...  Well 
> then you have to figure out what the UInt32 that is.

Hehe, that's harmless compared to those who will put a 

 do { ... lot's of code } while (0)

into a #define expansion ... cool trick, _almost_ an unnamed block
but a pain for FFI.

> 
> Bottom line though is when you are using FFI to call into C (and having 
> C call back!), it really does help to know some C.
> 
> Now am I the only one who keeps typing $_ instead of #_?  I blame Perl 
> for that.

Funny, happens to me all the time.

 Cheers Ralf Mattes
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel



More information about the Openmcl-devel mailing list