Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Objective-c > Re: Scope of va...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 10 Topic 991 of 1041
Post > Topic >>

Re: Scope of variables defined in .m files

by David Phillip Oster <oster@[EMAIL PROTECTED] > Jun 24, 2008 at 06:41 AM

In article 
<2008062407584675249-michaelhopkins@[EMAIL PROTECTED]
>,
 Michael Hopkins <michael.hopkins@[EMAIL PROTECTED]
> wrote:

> On 2008-06-20 13:39:17 +0100, Gregory Weston <uce@[EMAIL PROTECTED]
> said:
> 
> > In article <tu-dnQDAt7EO_cbVnZ2dnUVZ_oDinZ2d@[EMAIL PROTECTED]
>,
> >  Don Bruder <dakidd@[EMAIL PROTECTED]
> wrote:
> > 
> >> Well... Four days and nobody has shot it down... Does that mean I'm
safe
> >> in assuming that I got it right? :)
> > 
> > Nope. It means I never saw the post. The variables g, h, k and l exist
> > at the level of the compilation unit - the file. You could confirm
that
> > by writing a function outside the class that uses them (which would
> > succeed), or by declaring a second class in the same file that tries
to
> > redeclare the variables (which would fail).
> > 
> > The simplest way to achieve something like a class variable in Obj-C
is
> > to commit yourself to having a single class per implementation file
and
> > use static variables with file scope.
> 
> 
> Thanks for the input Gregory but I am still not sure if g, h, k & l are 
> per _class_ (i.e. shared by all instances of that class) or per 
> _object_ (i.e. each instance of the class has a separate version), and 
> whether the static modifier has any effect on this behaviour.
> 
> They are declared within the @[EMAIL PROTECTED]
 for a class but not as 
> instance variables and I have never seen this discussed anywhere.

It has been how many days?

Write a test program. run it. answer your own question here.

I think you'll find that statics declared in a .h file are neither per 
class nor per instance, they are per file. That is, if you include a.h 
in 1.m, 2.m, 3.m, they'll each get their own separate copy, a static 
var, of any static variables declared in the .h.
 




 10 Posts in Topic:
Scope of variables defined in .m files
Michael Hopkins <micha  2008-06-16 13:27:11 
Re: Scope of variables defined in .m files
Don Bruder <dakidd@[EM  2008-06-16 10:11:38 
Re: Scope of variables defined in .m files
Michael Hopkins <micha  2008-06-16 18:26:36 
Re: Scope of variables defined in .m files
Don Bruder <dakidd@[EM  2008-06-16 10:52:51 
Re: Scope of variables defined in .m files
Don Bruder <dakidd@[EM  2008-06-20 00:47:31 
Re: Scope of variables defined in .m files
Gregory Weston <uce@[E  2008-06-20 08:39:17 
Re: Scope of variables defined in .m files
Michael Hopkins <micha  2008-06-24 07:58:46 
Re: Scope of variables defined in .m files
David Phillip Oster <o  2008-06-24 06:41:34 
Re: Scope of variables defined in .m files
Gregory Weston <uce@[E  2008-06-24 12:30:10 
Re: Scope of variables defined in .m files
Justin Hibbits <chmeee  2008-06-17 07:21:52 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 11:02:35 CDT 2008.