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: 109fba,98ad5b2a2cd88a53 X-Google-Attributes: gid109fba,public X-Google-Thread: 103376,98ad5b2a2cd88a53 X-Google-Attributes: gid103376,public From: "Steve Doiel" Subject: Re: Ada or C++ acting 'correctly' here? Date: 1999/02/27 Message-ID: <36d83977.0@news.pacifier.com>#1/1 X-Deja-AN: 449351487 References: <7b8c7u$sj1@drn.newsguy.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 X-Trace: 27 Feb 1999 10:29:11 PST, 216.65.140.65 Newsgroups: comp.lang.ada,comp.lang.c++ Date: 1999-02-27T00:00:00+00:00 List-Id: >Now. Which would you consider the correct language behaviour? >(same machine, Pentium pro, Linux. > Both are giving the correct language behavior. For their language. The nature of C/C++ is to not notify you of overflows or suprises in calculations. The nature of Ada is to let you know when suprises occur. Your example is a good example of why I prefer Ada. Here's another. Consider the following C++ program #include void main() { int value = -4; unsigned divisor = 2; cout << value / divisor << endl; } Output: 214748364 And here's it's Ada Counterpart: WITH Ada.Integer_Text_Io; WITH Ada.Text_Io; WITH Interfaces; USE Interfaces; PROCEDURE Demo IS value : Integer_32 := -4; divisor : Unsigned_32 := 2; BEGIN Ada.Integer_Text_Io.Put( value / divisor ); Ada.Text_Io.New_Line; END Demo; Which gives a compile error: demo.adb:8:34: invalid operand types for operator "/" demo.adb:8:34: left operand has type "Interfaces.Integer_32" demo.adb:8:34: right operand has type "Interfaces.Unsigned_32" gnatmake: "demo.adb" compilation error The C++ program is more than happy to give you the wrong answer (as it must in accordance with the language standard). But the Ada compiler tells you you're doing something silly. BTW: I ran into this bug in a C program that was calculating an average where the sum was an integer and the count was unsigned. SteveD