home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / next / programm / 5366 < prev    next >
Encoding:
Text File  |  1992-07-30  |  2.7 KB  |  56 lines

  1. Newsgroups: comp.sys.next.programmer
  2. Path: sparky!uunet!nwnexus!sounds!brianw
  3. From: BrianW@SoundS.WA.com (Brian Willoughby)
  4. Subject: Re: Question about visibility of interface variables
  5. Message-ID: <Bs6yIF.35x@sounds.wa.com>
  6. Sender: brianw@sounds.wa.com (Brian Willoughby)
  7. Reply-To: BrianW@SoundS.WA.com
  8. Organization: SoundSoftware, Bellevue, WA, USA
  9. References: <1992Jul20.165042.15569@cs.mcgill.ca>
  10. Date: Thu, 30 Jul 1992 07:37:26 GMT
  11. Lines: 43
  12.  
  13. Darcy Brockbank writes
  14. | In article <20JUL92.11345443@enh.nist.gov> aoml@enh.nist.gov writes:
  15. | > I need to have a couple of variables which are specific to the particular
  16. | > nib section that is loaded.  (I have several of the same nib files on  
  17. | > screen at the same time, but each must have its own, discrete data set).  I
  18. | > figure that by putting these variables in the @interface section of the
  19. | > header file, they will be specific, like I need.  However, a large part of
  20. | > my file consists of regular C functions (which run faster, I think, than  
  21. | > methods).  When I put the variables in the @interface section, my functions
  22. | > can no longer see them.  I can see what is going on here, and where my  
  23. | > problem is.  Does anyone know of a better way of handling this than
  24. | > changing my functions into methods?  Thanks.
  25. | > Kevin
  26. | Variables declared in the interface section are global only to that object's
  27. | methods, and the subclasses of that object.
  28.  
  29. Actually, @interface variables are not global in the K&R sense.  They are local  
  30. variables whose scope includes the object and its subclasses.  Just like a  
  31. recursively called function will have multiple copies of the same variables,  
  32. multiple objects each have their own copy of the @interface variables - they  
  33. are not global.
  34.  
  35. | In order to make private variables that are also available to
  36. | an object's functions you can make static declarations within the
  37. |  .m file. You wan't have access to those variables from subclasses
  38. | though.
  39.  
  40. Warning: static variables are global and not created for each instance of the  
  41. object.  The original question indicated a need for each nib section that is  
  42. loaded to have its own discrete data set - static declarations will not provide  
  43. discrete instance variables.
  44.  
  45. To answer the original question, about the only way to have discrete instance  
  46. variables accessable by regular C functions would be to allocate a structure  
  47. every time you load the nib section and pass the pointer to this structure to  
  48. the regular C functions whenever you want to operate on a particular instance  
  49. of the nib.  Basically you would have to rewrite the Objective-C runtime - so  
  50. why not use it?
  51. -- 
  52. Brian Willoughby    Software Design Engineer, BSEE
  53. BrianW@SoundS.WA.com    SoundSoftware
  54. NeXTmail welcome
  55.