Re: Class hierarchy of exceptions (Ada, C++)
From: Peter Koch Larsen (pklspam_at_mailme.dk)
Date: 03/30/05
- Next message: Rolf Magnus: "Re: child and parent class args"
- Previous message: Profil1: "passing class to a function in c++ - performance question"
- In reply to: Tapio Kelloniemi: "Re: Class hierarchy of exceptions (Ada, C++)"
- Next in thread: Tapio Kelloniemi: "Re: Class hierarchy of exceptions (Ada, C++)"
- Reply: Tapio Kelloniemi: "Re: Class hierarchy of exceptions (Ada, C++)"
- Reply: fabio de francesco: "Re: Class hierarchy of exceptions (Ada, C++)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 30 Mar 2005 12:03:14 +0200
"Tapio Kelloniemi" <spam17@thack.org> skrev i en meddelelse
news:IQX1e.4368$sO2.1682@reader1.news.jippii.net...
> Ioannis Vranos <ivr@remove.this.grad.com> 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
But now you have problems calculating the velocity, right?
type Velocity is new Natural;
V: Velocity = M/S; // probably a compiler error.
> ...
> 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.
Not so. There is an excellent library which does exactly what you want -
using templates, of course.
>
> Such mistakes as using a pointer to nothing and writing past the array
> bounds don't often happen in Ada.
What makes you believe they happen regularly in C++?
>
>>An example. First compile with the default behaviour, then with all
>>warnings tu
>>rned on:
>>
>>int main()
>>{
>> int i=0;
>>
>> unsigned j=4;
>>
>> j<i;
>>}
>
> 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
I see no real difference here between a good-quality C++ compiler and Ada.
>
> --
> Tapio
/Peter
- Next message: Rolf Magnus: "Re: child and parent class args"
- Previous message: Profil1: "passing class to a function in c++ - performance question"
- In reply to: Tapio Kelloniemi: "Re: Class hierarchy of exceptions (Ada, C++)"
- Next in thread: Tapio Kelloniemi: "Re: Class hierarchy of exceptions (Ada, C++)"
- Reply: Tapio Kelloniemi: "Re: Class hierarchy of exceptions (Ada, C++)"
- Reply: fabio de francesco: "Re: Class hierarchy of exceptions (Ada, C++)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|