home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / mac / programm / 13966 < prev    next >
Encoding:
Text File  |  1992-08-13  |  2.2 KB  |  66 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!microsoft!wingnut!peterbak
  3. From: peterbak@microsoft.com (Peter Bako)
  4. Subject: death of a global variable...
  5. Message-ID: <1992Aug13.191303.17858@microsoft.com>
  6. Date: 13 Aug 92 19:13:03 GMT
  7. Organization: Microsoft Corp.
  8. Keywords: programming help, weird bug?
  9. Lines: 52
  10.  
  11.  
  12. I have a really weird bug that has me stumped, and just might do
  13. the same to some of you as well....
  14.  
  15. First of all a small background.  The program is being written on a
  16. Mac IIci with 8 megs of memory and running system 7.0.  The program
  17. is being written with Think C 5.0.2.
  18.  
  19. Now the problem.  I have two global variables, one which is an array 
  20. of menu handles, and the other is structure of my own design.  During
  21. an assign of two variables within the structure, the contents (first the
  22. lo order word, then the high) of the MenuHandle array get overwritten.
  23. Now for some code - first the structure:
  24.  
  25. typedef struct
  26. {
  27.     int        FileRefNum;
  28.     long    Height, Width;
  29.     int    dataPos;
  30.     WindowPtr    winPtr;
  31. } DrawRec;
  32.  
  33. Ok then I globally declare the following:
  34.  
  35. MenuHandle    theMenus[NumOfMenus];
  36. DrawRec        theImage;
  37.  
  38. During the setup look the MenuHandle array gets filled in with 4 handles
  39. to my four menus.  So far everything is working perfectly.  Now as the
  40. user selects the draw routine we jump to the setup for that which fills
  41. in the values of the struct:
  42.  
  43. /* get line of data into temp */
  44. StringToNum(temp, &x);
  45. theImage.Height = x;
  46. /* get next line of data */
  47. StringToNum(temp, &x);
  48. theImage.Width = x;
  49.  
  50. theImage.FileRefNum = refNum;
  51.  
  52. Now here is the catch!  By watching the value of theMenus[4] (my last menu)
  53. in the debugging window of Think C, I can watch how the contents of that
  54. variable are changed as the the value of theImage.Width and theImage.FileRefNum
  55. are set.  My problem is that I cannot figure out why by setting the these
  56. two variable, it is blowing away the contents of my menuHandle array.  Any
  57. ideas?
  58.  
  59. Peter
  60.  
  61. -- 
  62. (*)-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\/-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+(*)
  63. (   UUCP:         peterbak@microsoft  ||   Is this all that I am?  Is there   )
  64. (   CompuServe:   71170,1426          ||   nothing more?    - V'ger           )
  65. (*)-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-/\-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+(*)
  66.