swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

objectiveC/C question


From: Rick Riolo
Subject: objectiveC/C question
Date: Sat, 5 Feb 2000 15:13:36 -0500 (EST)

I have a question which probably falls at the edge
of objectiveC / C.

Suppose I have a few classes I am linking togther,
and the tops of the *.m files look like this:

Hare.m:
  unsigned int  nextID; 
  @implementation Hare
  ...
  @end

Fox.m:
  unsigned int  nextID;
  @implementation Fox
  ...
  @end

Plant.m
  extern unsigned int  nextID;
  @implementation Plant
  ...
  @end

Note the variable nextID is declared before and outside
of all method definitions for the classes.

If I compile and link these together, I get no complaints
and it runs as if there is just one bit of storage for nextID,
e.g., changing nextID to a new value in any class/file 
changes it for all.

Now (as expected) if I change, say Hare.m, to have
   static unsigned int  nextID;
then accessing that variable in the Hare methods
gives access to that nextID, but has no effect on nextID
accessible to the other classes.

But my question is:  Why without 'static' storage class 
declaration do all those declared nextID's in the
different *.m files get treated as one storage item
at link time?   

I guess it means the default is to make them 'auto', and then
auto variables with the same name (but in different *.m files)
get mapped to the same bit of storage...which (I guess) 
they would for variables declared auto outside
of C functions in different *.c files (if I recall correctly).
Is that right?  (I can't seem to find the explanation
in H&S right now...)

If that is the case, then does the 'extern' in the
above example make any difference in this case?
(again, note it is outside of any method).

thanks.

- r

Rick Riolo                           address@hidden
Center for Study of Complex Systems (CSCS)
4477 Randall Lab                
University of Michigan         Ann Arbor MI 48109-1120
Phone: 734 763 3323                  Fax: 734 763 9267
http://www.pscs.umich.edu/PEOPLE/rlr-home.html


                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]