[plt-scheme] foreign and C macros

From: Joe Marshall (jrm at ccs.neu.edu)
Date: Tue Mar 29 11:10:01 EST 2005

Eli Barzilay <eli at barzilay.org> writes:

>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> On Mar 28, David Van Horn wrote:
>> 
>> I was recently trying to rewrite my MySQL library to use foreign.ss
>> instead of cffi.ss.  Unfortunately the MySQL C API uses macros in
>> place of procedures for many of the library's functionalities.
>> 
>> Eg: #define mysql_num_rows(res) (res)->row_count
>> [...]
>> So is there a graceful solution to this problem using foreign.ss?
>
> Well, not really.  In the long run, it might be feasible to write a C
> header parser (Joe has something that's already working, but more work
> is required to actually use it), but for now there is no simple
> solution.

Ultimately, it cannot be done.  C macros simply don't have enough
information to be used other than in the context of a surrounding C
program.  Things like this:

#define offsetofclass(base, derived) ((DWORD_PTR)(static_cast<base*>((derived*)_ATL_PACKING))-_ATL_PACKING)

#define TRY { try {

#define END_TRY } catch (CException* e) \
	{ ASSERT(e->IsKindOf(RUNTIME_CLASS(CException))); e->Delete(); } }

#define EXTENSION_SNAPIN_DATACLASS(dataClass) dataClass m_##dataClass;

#define _SW( psz ) ATL::CStaticString< wchar_t, sizeof( L##psz ) >( L##psz )




Posted on the users mailing list.