Re: linking error?
Re: linking error?
- Subject: Re: linking error?
- From: Michael <email@hidden>
- Date: Mon, 4 Aug 2008 21:09:05 -0700
Thank you Andy and Jeffrey.
Having done C for 2 yrs now, and wanting to do it properly, I try not
to ask for others to spoon-feed me, but rather if people are kind
enough to explain and help out, it is greatly appreciated. Hence, your
answers are much appreciated.
I try ( even though on occasions I lapse) not to reply to "uncalled
for" remarks with the philosophy that it tends to say more about the
person answering than the person asking.
Michael.
On Aug 3, 2008, at 3:44 PM, Andy Lee wrote:
While I think the "2 minutes" remark may have been uncalled for
(maybe it was meant as a joke?), and while I too have a limited
memory for fine points (probably more so than you), you are
definitely missing something.
The *scope* of any static variable is the block in which it's
declared. If it's not in a block (i.e., not between any curly
braces), the scope is limited to the file. It isn't visible outside
of the file or block, and extern can't make it so. One consequence
of this is that you can define static variables with the same name
in different files.
The *lifetime* of a static variable in all cases is the duration of
the program, i.e., the variable keeps its value even if you exit the
block it was declared in.
A non-static variable that is not defined inside any block also
lives for the duration of the program, but it *can* be referenced
outside the file. You just have to declare the existence of the
variable, using extern, before using it. You can *declare* it
extern as many places as you want, but you can only *define* it
(i.e., tell the compiler to allocate memory for it) in one place.
The key distinctions are between scope and lifetime, and between
declaring and defining.
--Andy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden