home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / amiga / programm / 15653 < prev    next >
Encoding:
Text File  |  1992-11-10  |  1.5 KB  |  52 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: sparky!uunet!panther!mothost!lmpsbbs!supra.comm.mot.com!rittle
  3. From: rittle@supra.comm.mot.com (Loren James Rittle)
  4. Subject: Re: What is wrong with this very simple c program?
  5. Organization: Land Mobile Products Sector, Motorola Inc.
  6. Date: Tue, 10 Nov 1992 23:06:49 GMT
  7. Message-ID: <1992Nov10.230649.23472@lmpsbbs.comm.mot.com>
  8. Keywords: n
  9. References: <1992Nov10.184406.25907@sol.UVic.CA>
  10. Sender: news@lmpsbbs.comm.mot.com (Net News)
  11. Nntp-Posting-Host: 145.1.80.40
  12. Lines: 38
  13.  
  14. In article <1992Nov10.184406.25907@sol.UVic.CA> aramsey@ugly.UVic.CA (Aaron  Ramsey) writes:
  15.  
  16. <the following program crashes, why?>
  17. [reformatted so I can stay sane.]
  18.  
  19. >#include <stdio.h>
  20. >
  21. >main()
  22. >{
  23. >   int zoop[1000];
  24. >   int counter;
  25. >     
  26. >   printf ("started....");
  27. >   for (counter = 0; counter < 5000; counter += 5)
  28. >     {
  29. >       zoop[counter] = counter;
  30. >     }
  31. >   printf("done....");
  32. >}
  33.  
  34. Note that you write zoop[] past the end of the array!  zoop[999] is the
  35. highest valid location in zoop[], you write into zoop[4995]. Did you
  36. mean to divide counter by 5 or something before using it to refer into
  37. zoop[]?
  38.  
  39. My guess is that you are overwriting a stack frame or/and return
  40. address pointer.  The exact thing you are doing would be implementation
  41. dependent - it would depend on the layout of the stack and stack
  42. frames.  BTW, yes, this error would most likely not cause the program
  43. to crash until main() returns.
  44.  
  45. Regards,
  46. Loren
  47. --
  48. Loren J. Rittle (rittle@comm.mot.com)
  49. Systems Technology Research (IL02/2240)
  50. Motorola, Inc.
  51. (708)576-7794
  52.