From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1014db,dab7d920e4340f12 X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,dab7d920e4340f12 X-Google-Attributes: gid103376,public From: john@polo.demon.co.uk (John Winters) Subject: Re: C is 'better' than Ada because... Date: 1996/06/23 Message-ID: #1/1 X-Deja-AN: 161667899 x-nntp-posting-host: polo.demon.co.uk references: <4q8fbo$701@red.interact.net.au> <31CC75C1.5BF2AF6A@jinx.sckans.edu> organization: Wallingford newsgroups: comp.lang.c,comp.lang.ada Date: 1996-06-23T00:00:00+00:00 List-Id: In article <31CC75C1.5BF2AF6A@jinx.sckans.edu>, David Morton wrote: >> >> ======= the C program >> >> #include >> main() >> { >> int vec[5]; >> int i; >> >> for(i = 0 ; i < 10 ; i++ ) >> { >> vec[i] = i; >> cout<< " current value is " << vec[i] << endl; >> } >> >> } >> >> $CC test1.cc >> $a.out >> current value is 0 >> current value is 1 >> current value is 2 >> current value is 3 >> current value is 4 >> current value is 5 <--- Nice !! C/C++ allows me to the freedom to loop >> current value is 6 I dont have to change my code :) >> current value is 7 >> current value is 8 >> current value is 9 >> >> Nasser >> -- >> Nasser Abbasi. C/C++/Ada Solaris. GeneAssist - A client/server application >> for Nucleic acid and protein sequence search and analysis. >> PE-Applied BioSystem division. email: nasser@apldbio.com >> MSEE(control), MSCS, MSCE, FM(Fide Chess Master 2305 ELO 1.e4 !!) > > >I get: > > current value is 0 > current value is 1 > current value is 2 > current value is 3 > current value is 4 > current value is 5 > current value is 6 > current value is 7 > current value is 8 > current value is 9 >Segmentation fault > > >so that c code *will* have to be changed... >But I am curious why it did seg fault sooner? >(BTW, That's why I'm posting this back to comp.lang.c) >Can anyone tell me why this doesn't seg fault sooner? >OS is Linux 2.0, GNU g++ In the eyes of the C language, anything is possible here, but the probable reason it seg faulted where it did is that you overwrote the bit of the stack holding the return address from the routine. When the routine tried to return it instead shot off into the wild blue yonder. The observant will have noticed that the sample code isn't written in C anyway. John -- John Winters. Wallingford, Oxon, England.