Amazon.com Widgets Question on Static Variables
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 18, 2014, 06:47:30 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
| | | |-+ Question on Static Variables
Pages: [1] Go Down
Print
Author Topic: Question on Static Variables (Read 615 times)
BFB
Newbie
*
Posts: 6


Email




on: October 07, 2011, 11:05:40 PM

3rd Ed. pg 204

why is gCounter declared in each of the allocF and count methods? If it's a static variable, can't each method just access it and use it how they want? It seems the
Code: (Objective-C)
extern int gCounter;
line of code is completely unnecessary. Can the allocF method simply increment the gCounter variable without having to redeclare it? Isn't that the whole point of a static variable: declare it once and have it accessible by all the methods in that module?
Logged
dharr19
Full Member
***
Posts: 175


Email




Reply #1 on: October 08, 2011, 01:56:02 AM

Hi,

Thats correct, its not necessary. "The extern declarations are not required in the two methods ... It simply helps the reader understand that a variable defined outside the method is being accessed."

Hope this helps
David
Last Edit: October 08, 2011, 01:58:44 AM by dharr19 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.