Welcome, Guest. Please login or register.
Did you miss your activation email?
April 26, 2017, 12:35:14 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
Author Topic: Question on Static Variables (Read 1224 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:

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.