March 04, 2007 Static initalization of global variable? | ||||
---|---|---|---|---|
| ||||
I keep getting bitten by things that seem obvious. I'm trying to do this: import ...CFString; CFStringRef kHIAboutBoxNameKey; static { kHIAboutBoxNameKey = CFSTR("HIAboutBoxName"); } But GDC 0.22 complains with: "no identifier for declarator kHIAboutBoxNameKey". I don't even know what this is telling me. I basically want a variable to hold a (constant) value that other code can use. In this case, CFStringRef is a pointer to a struct type declared in CFString. What must I do? TIA, Rick |
March 04, 2007 Re: Static initalization of global variable? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rick Mann | Rick Mann wrote:
> I keep getting bitten by things that seem obvious. I'm trying to do this:
>
> import ...CFString;
>
> CFStringRef kHIAboutBoxNameKey;
>
> static
> {
> kHIAboutBoxNameKey = CFSTR("HIAboutBoxName");
> }
>
>
> But GDC 0.22 complains with: "no identifier for declarator kHIAboutBoxNameKey".
>
> I don't even know what this is telling me. I basically want a variable to hold a (constant) value that other code can use. In this case, CFStringRef is a pointer to a struct type declared in CFString. What must I do?
The static {} block isn't something that gets executed (as it would be in e.g. Java), it just means that all declarations in it will have the attribute "static". What you put into it isn't a declaration, so that's what it complains about. Your options:
---
CFStringRef kHIAboutBoxNameKey = CFSTR("HIAboutBoxName");
---
(if CFSTR() can be evaluated at compile time)
or
---
CFStringRef kHIAboutBoxNameKey;
static this()
{
kHIAboutBoxNameKey = CFSTR("HIAboutBoxName");
}
---
(where CFSTR() gets run at the start of the program)
|
Copyright © 1999-2021 by the D Language Foundation