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



A while back, Steve Zellers posted the following:

> CFSTR, when compiled on 10.2 or later with GCC 3.x with
> -fconstant-cfstrings will lay out a memory object with your CFString in
> your TEXT section; it'll be as efficient as possible.

So in this case, using a macro as Jim suggested will do essentially what you
want.

Otherwise, CFSTR is actually a function which takes a key and returns a
CFStringRef, and you can't do that with a global (outside a function)
variable. Or at least I've never figured out a way to do it.

Out of curiosity, why do you want to do this?

Larry

On 8/27/03 12:41 PM, Jim Hamilton didst favor us with:

> On Wednesday, August 27, 2003, at 11:51 AM, Marc Poirier 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 I need to use __attribute__((constructor)) or something else, or is
>> there some CoreFoundation trick to use?
>
> How about:
>
> #define blah CFSTR("blah")
>
> Yes, there's been lots of talk on the list in the last day about evil
> macros (especially around type checking), but sometimes they're
> appropriate, and this one has the correct type.
>
> Jim H
_______________________________________________
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.

References: 
 >Re: static CFSTR in C (From: Jim Hamilton <email@hidden>)



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.