• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Future Objective-C changes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Future Objective-C changes


  • Subject: Re: Future Objective-C changes
  • From: Andy Lee <email@hidden>
  • Date: Wed, 21 May 2003 11:57:45 -0400

At 4:51 PM +0200 5/21/03, Marcel Weiher wrote:
I have never ever heard anyone refer to "defining" a local variable, though that doesn't mean it has never happened.

I think someone pointed this out, but "declare" and "define" have very specific meanings in C. The key distinction is not between local vs. global variables. It is between announcing ("declaring") the existence of a variable name (meanwhile specifying the data type of the variable) vs. telling the compiler to allocate a memory location for it ("defining" it).

A local variable declared like this...

{
int localInt;
...
}

...is defined at the same time, by the same statement. It *has* to be, because by definition the memory allocated for a local variable is freed when the variable's scope is exited. So it wouldn't make sense to talk specifically about "defining" a local variable; it goes without saying. *That* is probably why you have never heard anybody say such a thing, not because there is different terminology for local and non-local variables.

As another example of the distinction: a non-local variable can be declared multiple times, but it can only be defined once. You can say this...


extern int globalInt; // declaration


...as many times as you want, but you must say this...


int globalInt; // definition which is also a declaration


...exactly once.

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

References: 
 >Re: Future Objective-C changes (From: Marcel Weiher <email@hidden>)

  • Prev by Date: Re: Future Objective-C changes
  • Next by Date: Re: Multiple Targets in Project Builder
  • Previous by thread: Re: Future Objective-C changes
  • Next by thread: Re: Future Objective-C changes
  • Index(es):
    • Date
    • Thread