How to convert C macro that calls function returning a struct*?
Rick Mann
rmann-d-lang at latencyzero.com
Mon Jan 29 23:04:14 PST 2007
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 tried doing this:
struct __CFString {};
typedef const __CFString* CFStringRef;
template CFSTR(char[] inS)
{
const CFStringRef CFSTR = __CFStringMakeConstantString(inS.ptr);
}
extern (C) CFStringRef __CFStringMakeConstantString(char* cStr);
But I get the following errors:
src/d/darbon/examples/GrabBag/GrabBag.d:49: Error: non-constant expression (__CFStringMakeConstantString)("darbon.grabbag.demoview")
../../src/d/macos/corefoundation/CFString.d:152: Error: non-constant expression (__CFStringMakeConstantString)("darbon.grabbag.demoview")
The first occurs on this line:
const CFStringRef viewID = CFSTR!("darbon.grabbag.demoview");
and the second error is referring to the line inside the template definition.
I'm at a loss. I need to be able to define constants that effectively call __CFStringMakeConstantString(), and I need to be able to call it directly. Any suggestions? (GDC 0.27/DMD 1.00).
Thanks!
More information about the Digitalmars-d-learn
mailing list