How to convert C macro that calls function returning a struct*?
Anders F Björklund
afb at algonet.se
Tue Jan 30 00:05:55 PST 2007
Rick Mann wrote:
> I've run into a problem creating D bindings for the Mac OS X Carbon API. In particular, I'm trying to find a way to implement the following C macro (context provided):
>
> typedef const struct __CFString * CFStringRef;
> #define CFSTR(cStr) __CFStringMakeConstantString("" cStr "")
> CFStringRef __CFStringMakeConstantString(const char *cStr);
> #define kSomeCFStringConstant CFSTR("myCFStringConstantValue");
I used this:
struct __CFString { }
typedef __CFString* CFStringRef;
typedef __CFString* CFMutableStringRef;
extern (C) CFStringRef __CFStringMakeConstantString(char *cStr);
alias __CFStringMakeConstantString CFSTR; // only for string literals
Generally speaking C macros map into D functions, but for simple
renames one can make use of "alias" to avoid the extra object code.
It only works for ASCII strings, by the way, for regular D strings
you need to specify using the UTF-8 encoding to Core Foundation...
--anders
More information about the Digitalmars-d-learn
mailing list