Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: static CFSTR in C



On Wed, 27 Aug 2003 09:59:23 -0700 Marshall Clow <email@hidden> wrote:
>
> Marc Poirier <email@hidden> wrote:
>
>> Hi. I was wondering, is there a way to use CFSTR for a global
>> variable in C? Does something like this (outside of a function):
>> static const CFStringRef blah = CFSTR("blah");
>> results in this error:
>> error: initializer element is not constant
>
> Do this instead:
>
> CFStringRef GetBlah () {
> static const CFStringRef blah = CFSTR("blah");
> return blah;
> }

Hi Marshall,

The question was about C and what you suggest is illegal in C.
As illegal as using it outside a function. In C that should be:

CFStringRef GetBlah (void) {
static const CFStringRef blah = NULL;
if (!blah) blah = CFSTR("blah");
return blah;
}

Mike
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.