Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Here is a third proof that C++ and C are bad

50 views
Skip to first unread message

Ramine

unread,
Dec 28, 2015, 12:24:24 PM12/28/15
to
Hello.....


How can you test for signed int overflow..

Here is how you can do it in C and C++:

===
#include <limits.h>
int a = <something>;
int x = <something>;
if ((x > 0) && (a > INT_MAX - x)) /* `a + x` would overflow */;
if ((x < 0) && (a < INT_MIN - x)) /* `a + x` would underflow */;
/* ... same thing for subtraction, multiplication, and division */
===


But notice with me that this method in C and C++ is not
acceptable for realtime safety critical systems, because
on a more complex software for realtime safety critical systems,
you can forget to test for overflow of the integer and this can have a
bad consequence and even a catastrophe, so C++ and C are bad.

But with the Delphi mode of the FreePascal compiler you can do this:

Compile with -Cr(for range checking) and compile with -Co(for Integer
overflow checking), so even if on a more complex software for realtime
safety critical system you have forgot to test for for overflow of a
signed int or an unsigned integer , you can effectively catch the
exception of the overflow signed int or unsigned int with a Try Except
End; in the Delphi mode of FreePascal if you compile block with -Cr and
-Co, and that's better in FreePascal for realtime safety critical
systems, note also that i have just tested FreePascal with -Co and it
works for both overflow of a signed int or an unsigned int.



Thank you,
Amine Moulay Ramdane.












Ramine

unread,
Dec 28, 2015, 12:42:45 PM12/28/15
to

Hello....


I have just tested -Co compiler option of the FreePascal
compiler, it will throw an exception that you can catch
from the software for both overflow and underflow.

Mr Flibble

unread,
Dec 28, 2015, 1:49:06 PM12/28/15
to
Your basic point which you are annoyingly repeatedly expressing in
various different but similar ways as extremely annoying spam posts is
that C++ has undefined behaviour. The presence of undefined behaviour
bestows certain benefits to C++ the primary one being that of
performance. Languages which lack undefined behaviour tend to be much
slower than those that do such as C++.

Although the C++ language benefits from having undefined behaviour
actually invoking it is a BUG so the question as to whether a language
with undefined behaviour can be used in safety critical systems is
answered by the realisation that you can also create bugs in a language
with no undefined behaviour.

So instead of banging on about C++ you should restrict your argument to
languages in general that either do or don't exhibit undefined behaviour
and how bugs manifest in those languages sausages.

/Flibble

0 new messages