Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
August 22, 2017, 07:39:35 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: Question on Static Variables  (Read 1271 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:  

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 ゥ 2009 classroomM.com. All rights reserved.