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: 103376,dab7d920e4340f12 X-Google-Attributes: gid103376,public From: nasser@apldbio.com (Nasser Abbasi) Subject: Re: C is 'better' than Ada because... Date: 1996/06/30 Message-ID: #1/1 X-Deja-AN: 162861698 sender: news@biosys.apldbio.COM references: <4q8fbo$701@red.interact.net.au> original-sender: nasser@apldbio.com organization: Applied BioSystems newsgroups: comp.lang.ada Date: 1996-06-30T00:00:00+00:00 List-Id: From: joeuser@satcom.whit.org (joeuser) Newsgroups: comp.lang.ada Date: 27 Jun 1996 01:19:55 GMT Was this to be a spoof? Why would one want to read past the limits of ones array? Who knows what ^^^ might be in that area of memory? Chances are, it is the next thing you declared. Then again, maybe not, depending just where in memory this array is located. Why? it seems the answer is obviouse. Becuase humans make mistakes. a programmer can use the wrong arrray range to loop. It is not like they would do it intnentionaly. In Ada it will be cought, in plain C/C++ it would not. (some said that some C/C++ compiler do range checking). In Ada it is hard to use the wrong array range to start with becuase you say A'Range, and even if you do, the run-time will tell you if you did. Next: If you are using an array that changes sizes frequently, perhaps you should use some other data structure. Foregoing that, at least declare your array dynamically. this is beside the point of the example to show that C/C++ did not do range checking. What does declaring an array dynamically has to do with range checking? Finally: If you are still insistant on declaring a static array, at least do it this way. . . optinal --> integer . v Size_Of_Array : constant := 5; . . . Vec: array(1..Size_Of_Array) of integer; . . . end Main; Yes, sure nice, I think we know that , But Again, this is beside the point of the example. I still cannot think of any reason to even attempt to write values beyond the constraints of the array and into unknown memory. I really would like to hear any REAL arguments as to why one would desire, and especially NEED, to do this. a REAL argument is that programmers make mistakes and it is easier in C/C++ to do such mistakes and not know about them becuase the compiler/run-time do not tell you about them. in C/C++ you might spend hours looking for such a bug especially if the program is large, involving many arrays or matrices, and they are being passed around different functions to process, etc.. I've seen programs in C that were using wrong array range calculations, yet have been running with no apparent problems, but someday would crash, or behave funny, and one would just start the program again, and in few days it might crash again, etc.. Offcourse there are super C/C++ programmers who never make mistakes such as using the wrong array size, and then this discussion do not apply to them. In article , nasser@apldbio.com says... > I've finally become convinced that C really IS better than Ada, > for the following reasons: > snip.. > >========= The Ada program > >with Ada.Text_Io; use Ada.Text_Io; >procedure Main is > I: Integer :=0; > Vec : array(1..5) of Integer; >begin > for I in 1..10 loop > Vec(I):=I ; > Put_Line(" Current value is "& Integer'Image(Vec(I))); > end loop; >end Main; > Output omitted... > >======= 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; > } > >} > Output omitted... BTW. I think a validated compiler will catch that constraint error at compile time. Dont know about that. I used the C++ compiler on my SOlaris 2.5 station and it let me loop outside the array boundary. If better C/C++ compilers will catch this type of error, that is fine, that's one more hole in C/C++ we've patched up untill the next one shows up. 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 1.e4 !! 1-0 )