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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!nntp.abs.net!newsfeed1.swip.net!swipnet!newsfeed1.funet.fi!newsfeeds.funet.fi!feeder1.news.jippii.net!reader1.news.jippii.net!53ab2750!not-for-mail From: Tapio Kelloniemi Subject: Re: Class hierarchy of exceptions (Ada, C++) References: <1112027876.946645@athnrd02> Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng Message-ID: Date: Mon, 28 Mar 2005 18:15:04 GMT NNTP-Posting-Host: 217.30.176.187 X-Complaints-To: newsmaster@saunalahti.com X-Trace: reader1.news.jippii.net 1112033704 217.30.176.187 (Mon, 28 Mar 2005 21:15:04 EEST) NNTP-Posting-Date: Mon, 28 Mar 2005 21:15:04 EEST Organization: Saunalahti Customer Xref: g2news1.google.com comp.lang.ada:10082 comp.lang.c++:47639 comp.realtime:1786 comp.software-eng:5422 Date: 2005-03-28T18:15:04+00:00 List-Id: Ioannis Vranos wrote: >Ioannis Vranos wrote: > >> Actually most compilers provide warnings for lots of stuff and provide >> an option to display all warnings (e.g. /Wall), even comparison between >> signed and unsigned integers generates a warning. And they can also >> treat all warnings as *errors* if you specify so. >> >> However the default is to display warnings for anything that is not >> required by the standard to be treated as an error, and compile it. >> >> >> In most cases, one fixes *all* warnings. However there *are* some cases >> where the programmer knows better. >> >> C++ is enabling by default, which I suppose is the opposite direction of >> Ada, and that's why I think we can't understand one another. :-) >> >> >> C++ being less restrictive as the default, doesn't mean a compiler does >> not generate lots of warnings! The question is not only about compiler warnings or errors. Ada (as a language) has been designed so that it is possible for the compiler to check many mistakes which may cause bad results at run time. Ada also makes it easier for the user to notice this kind of errors. For example: procedure X is type Metres is new Natural; type Seconds is new Natural; M : Metrses := 0; S : Seconds := 10; begin if M < S then -- Error, < is not defined for these types ... end if; end X; This is a bit more verbose than using pure int instead of Metres and Seconds, but if I wanted a C++ compiler to check this kind of error, I'm afread that the resulting C++ code would be much more verbose. Such mistakes as using a pointer to nothing and writing past the array bounds don't often happen in Ada. >An example. First compile with the default behaviour, then with all warnings tu >rned on: > >int main() >{ > int i=0; > > unsigned j=4; > > j} procedure Temp is I : Integer := 0; J : Natural := 4; begin I < J; end Temp; Without any warnings: # gnatmake temp gcc -c temp.adb temp.adb:5:05: missing ":=" gnatmake: "temp.adb" compilation error Notice how the language prevents doing useless things. If a replace I < J; with null; the result is: gcc -c -gnatg temp.adb temp.adb:2:04: warning: "I" is not modified, could be declared constant temp.adb:2:04: warning: variable "I" is not referenced temp.adb:3:04: warning: "J" is not modified, could be declared constant temp.adb:3:04: warning: variable "J" is not referenced gnatmake: "temp.adb" compilation error -- Tapio