public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Robert Dewar <dewar@adacore.com>
To: Michael Veksler <VEKSLER@il.ibm.com>
Cc: gcc@gcc.gnu.org
Subject: Re: The utility of standard's semantics for overflow
Date: Wed, 29 Jun 2005 08:42:00 -0000	[thread overview]
Message-ID: <42C25EDF.4010700@adacore.com> (raw)
In-Reply-To: <OFD3D9025B.5DBCC2A3-ON4325702F.002AE087-4325702F.002EEDDD@il.ibm.com>

Michael Veksler wrote:

> If the programmer wants a robust application,
> then casting to unsigned must be present for almost any
> usage of int.

If you have a variable in your program that is signed but must
always be in the range of int, then int is the appropriate
representation. If the pressure in a tank must be in the
range -2**31 .. +2**31-1, it does not make the application
more robust to ensure that if the pressure goes "over" the max, it
suddenly turns negative. That's likely to be just as
disastrous as any other behavior in this serious error
situation.

In practice of course, the pressure in this example is
likely to be in a much more constrained range, and part
of making a "robust application" will be to ensure that
the value always remains in the required range. In a more
expressive language like Ada, the corresponding type would
be declared with the appropriate range, and an exception
would be raised if the value is outside this range.

In practice in a critical application, you are likely to
not want any exceptions, so proving such a program exception
free is one of the tasks that faces the applications programmer
in writing a reliable program. See for example:

http://www.praxis-cs.com/pdfs/Industrial_strength.pdf

  reply	other threads:[~2005-06-29  8:42 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-29  8:33 Michael Veksler
2005-06-29  8:42 ` Robert Dewar [this message]
2005-06-29  9:04   ` Michael Veksler
2005-06-29  9:18     ` Robert Dewar
2005-06-29  8:48 ` Eric Botcazou
2005-06-29 11:16   ` Michael Veksler
2005-06-29 16:19     ` Eric Botcazou
2005-06-29  9:47 ` Theodore Papadopoulo
2005-06-29 12:14   ` Robert Dewar
2005-06-29 13:12     ` Dave Korn
2005-06-29 13:35       ` Robert Dewar
2005-06-29 18:37       ` Olivier Galibert
2005-07-01 18:22         ` Alexandre Oliva
2005-07-01 18:30       ` Alexandre Oliva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42C25EDF.4010700@adacore.com \
    --to=dewar@adacore.com \
    --cc=VEKSLER@il.ibm.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).