Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
May 21, 2018, 10:09:18 AM *
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
Author Topic: Question on Static Variables  (Read 1394 times)
Posts: 6

« 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?
Full Member
Posts: 175

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


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
« Last Edit: October 08, 2011, 01:58:44 AM by dharr19 » Logged
Pages: [1]   Go Up
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 All rights reserved.