Amazon.com Widgets usage of extern pg 209
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 25, 2013, 11:42:33 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Chapter Study
| | |-+  Chapter 10 - More on Variables and Data Types
| | | |-+  usage of extern pg 209
Pages: [1]   Go Down
Print
Author Topic: usage of extern pg 209  (Read 925 times)
Mike
Jr. Member
**
Posts: 51


Email




« on: April 12, 2009, 11:29:53 AM »

I'm really not sure about extern.  I guess to start from the beginning, the @interface section declares instance variables and methods while the @implementation section defines instance variables and methods.  At this point it sounds like extern is used to declare a instance variable that has been defined or declared already?   Given that we have inheritance in OOP I don't understand the concept of it.

Thanks
Mike
Logged
skochan
Administrator
Hero Member
*****
Posts: 3106







« Reply #1 on: April 12, 2009, 12:59:08 PM »

extern is not used for instance variables.  It's used to reference variables defined outside of any method or function, possibly even in another source file.  This allows you to create variables whose is scope is global.  These global variables don't belong to any method or function (that is, they're not local) and therefore their values can be shared among multiple methods and functions.

Cheers,

Steve

« Last Edit: April 12, 2009, 01:14:22 PM by skochan » Logged
Mike
Jr. Member
**
Posts: 51


Email




« Reply #2 on: April 12, 2009, 01:51:33 PM »

On page 210 I see

 int gGlobalVar = 5 

Since this is defined then any method or function can use it.  So if I wanted to use gGlobalVar in my implentation file I would add extern gGlobalVar at the top of that file?

Thanks
Mike

 
Logged
skochan
Administrator
Hero Member
*****
Posts: 3106







« Reply #3 on: April 12, 2009, 01:56:41 PM »

Yes, or from a self-documenting point of view, put individual extern declarations inside the particular method(s) that wanted to access the variable.

Cheers,

Steve
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.