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: const vs. static CFStringRefs



I guess I was asking more along the lines of memory allocation in the compiled file. I should have stated my question differently. I'm guessing the "static" version is a single memory allocation that can be referenced multiple times. Does the "const" version end up being the same, or is it perhaps allocated every time it's referenced? This all gets confusing in my head as I know that CFSTR is doing some behind-the-scenes stuff and I don't know what that is.


On Nov 29, 2005, at 5:42 PM, John Stiles wrote:

At global scope, right?
The "const" version cannot be changed to point to a separate CFStringRef; the compiler prohibits you from writing:
kStringRef1 = CFSTR("another string"); // <-- illegal


The "static" version, unlike the "const" version, is not given global linkage. It cannot be referenced from another file via extern, like so:
extern const CFStringRef sStringRef1; // <-- illegal


You can combine these properties to create a CFStringRef which cannot be changed and does not have global linkage:
static const CFStringRef k_stringRef3 = CFSTR("local and unchanging string");


In function scope, the meaning of "const" is the same, and "static" is a little different. You can look it up in any C++ reference book for details :)


On Nov 29, 2005, at 5:34 PM, Stevo Brock wrote:

What would be the difference between declaring CFStringRefs const vs. static in a single source file? As in...

const	CFStringRef	kStringRef1 = CFSTR("string1");

vs.

static	CFStringRef	sStringRef2 = CFSTR("string2");

Is there any difference? Is there any difference if they are used once or more than once in the file?

Curious...

-Stevo Brock
 Monkey Tools
 www.monkey-tools.com

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/jstiles% 40blizzard.com


This email sent to email@hidden



_______________________________________________ Do not post admin requests to the list. They will be ignored. Carbon-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden
References: 
 >const vs. static CFStringRefs (From: Stevo Brock <email@hidden>)
 >Re: const vs. static CFStringRefs (From: John Stiles <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.