How to convert C macro that calls function returning a struct*?
Lionello Lunesu
lio at lunesu.remove.com
Tue Jan 30 00:09:42 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 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!
>
Try dropping the const from the typedef.
L.
More information about the Digitalmars-d-learn
mailing list