home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.amiga.programmer
- Path: sparky!uunet!panther!mothost!lmpsbbs!supra.comm.mot.com!rittle
- From: rittle@supra.comm.mot.com (Loren James Rittle)
- Subject: Re: What is wrong with this very simple c program?
- Organization: Land Mobile Products Sector, Motorola Inc.
- Date: Tue, 10 Nov 1992 23:06:49 GMT
- Message-ID: <1992Nov10.230649.23472@lmpsbbs.comm.mot.com>
- Keywords: n
- References: <1992Nov10.184406.25907@sol.UVic.CA>
- Sender: news@lmpsbbs.comm.mot.com (Net News)
- Nntp-Posting-Host: 145.1.80.40
- Lines: 38
-
- In article <1992Nov10.184406.25907@sol.UVic.CA> aramsey@ugly.UVic.CA (Aaron Ramsey) writes:
-
- <the following program crashes, why?>
- [reformatted so I can stay sane.]
-
- >#include <stdio.h>
- >
- >main()
- >{
- > int zoop[1000];
- > int counter;
- >
- > printf ("started....");
- > for (counter = 0; counter < 5000; counter += 5)
- > {
- > zoop[counter] = counter;
- > }
- > printf("done....");
- >}
-
- Note that you write zoop[] past the end of the array! zoop[999] is the
- highest valid location in zoop[], you write into zoop[4995]. Did you
- mean to divide counter by 5 or something before using it to refer into
- zoop[]?
-
- My guess is that you are overwriting a stack frame or/and return
- address pointer. The exact thing you are doing would be implementation
- dependent - it would depend on the layout of the stack and stack
- frames. BTW, yes, this error would most likely not cause the program
- to crash until main() returns.
-
- Regards,
- Loren
- --
- Loren J. Rittle (rittle@comm.mot.com)
- Systems Technology Research (IL02/2240)
- Motorola, Inc.
- (708)576-7794
-