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

David Steuber david at david-steuber.com
Wed Dec 22 20:32:31 UTC 2004


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 ;-)

> 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, 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.

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.




More information about the Openmcl-devel mailing list