home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / msdos / programm / 12009 < prev    next >
Encoding:
Text File  |  1993-01-12  |  1.7 KB  |  60 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!mcsun!sunic!dkuug!daimi!aau!psykseth
  3. From: psykseth@aau.dk (Seth Chaiklin)
  4. Subject: GLOBAL structs > 64K
  5. Message-ID: <1993Jan12.115830.1043@aau.dk>
  6. Organization: Aarhus University, Denmark
  7. Date: Tue, 12 Jan 1993 11:58:30 GMT
  8. Lines: 50
  9.  
  10. Harvey Shulman posted the following code for making a structure that was
  11. greater than 64K:  (thanks Harvey!)
  12.  
  13. #include  <stdio.h>
  14. #include  <stdlib.h>
  15. #include  <alloc.h>
  16.  
  17. void main()
  18. {
  19. int  i;
  20. typedef struct yynew {int current, advance;} yynew;
  21. yynew  *yycrank, j;
  22.  
  23. /* in the allocation statement I could not see why you used 20000L.
  24.    after all 20000 is 20000, isn't it? */
  25.  
  26. yycrank = farmalloc(20000 * sizeof(yynew));
  27. for (i = 0; i < 20000; i++)
  28.  { j.current = 0;
  29.     j.advance = i;
  30.     *(yycrank+i) = j ;
  31.  };
  32. }
  33.  
  34.  
  35. This compiled for me as well, and as Ian Gray pointed out, it is critical to
  36. make it 20000L and not just 20000.  Try it in the debugger and see the
  37. difference.
  38.  
  39. He also mentioned that:
  40.  
  41. > in the above loop I tried several variants of assignment to the
  42. > fields of yycrank's records without success.  Maybe someone else can
  43. > describe how to do such things as   *(yycrank+i).current = 0
  44.  
  45. I also had problems like that.  I never did figure that out, and I don't
  46. understand why it is a problem.
  47.  
  48. However, I still haven't gotten my REAL problem across which is that
  49. I want to make this definition GLOBAL!  As I mentioned in my original
  50. post, I can do all these things inside of a function, but I want to
  51. make this initialization global so that I can use the initialization
  52. to initialize some other structures.  Everything falls apart for me
  53. when I try to make these same definitions outside of a function.
  54.  
  55. Any pointers would be appreciated.
  56.  
  57. Cheers,
  58.   Seth
  59.  
  60.