Re: C return a++ - is it safe?



In data Thu, 01 Nov 2007 09:56:28 -0500, CBFalconer scrisse:
Chris Hills wrote:
Dave Hansen writes
Chris Hills <ch...@xxxxxxxxxxxx> wrote:
Richard Harter <c...@xxxxxxxx> writes

... snip ...

Offhand, I would think that it is the sort of thing that a
compiler could be expected to get right but I might well be
wrong.

In other words you wouldn't bet your life on it....

In that case (betting my life), Ada has no advantage over C.

Absolutely,.... For years I have been arguing there is no such
thing as a "safe" language. It is all down to the quality of the
implementation

Yes, no language is 'safe'. However, some are much safer than
others. For example, the presence of subtypes (such as Pascals
ranges) simply allows range checking everywhere. Whenever a
construct creates a value for that item that is known to be out of
range, the compiler complains. When a runtime operation exceeds
that range, the runtime complains. Similarly the accurate control
of pointers allows most misuse of pointer variables to be detected
_at compile time_. This is a great advantage over C.

i think i'm in your kill file so don't read what i write;

the same for very pedands ones

-----------------------------------------------------------------
------------------------------------------------------------------
you and other seems not understand the esistance of variables that
*can not* overflow e.g. size_t; or
int, unsigned, float, double etc in financial calculis etc etc

if some of that variables has an overflow it has to rappresent an
error number (eg: INT_MAX for +overflow and INT_MIN for -overflow)
so detect errors in run time is more easy

for an unsigned thype the aritimetic is very easy

0..UMAX

a+b = (a==UMAX || b==UMAX || oveflow(a+b)? UMAX : sum(a, b);
a-b = (a==UMAX || b==UMAX || a<b || oveflow(a-b)? UMAX : sum(a, b);

some like above for -*/

0..UMAX-1 is ok
UMAX is an error

Unfortunately Pascal seems to have largely disappeared as a major
language. We are left with its descendent, Ada, which is a larger,
safer, and tested language. And also available in gcc.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
.



Relevant Pages

  • Re: C return a++ - is it safe?
    ... In other words you wouldn't bet your life on it.... ... Yes, no language is 'safe'. ... range, the compiler complains. ... of pointers allows most misuse of pointer variables to be detected ...
    (comp.lang.c)
  • Re: Loop until condition is true
    ... Benji York wrote: ... test in "while True", then this is a compiler issue, not a language issue. ... I don't know anything about the Python compiler internals, but it doesn't seem very hard to identify simple literals following while and if, and to skip the runtime test. ... into programming language syntaxes to make life a little easier for ...
    (comp.lang.python)
  • Re: "STL from the Ground Up"
    ... high-level intermediate language than can interoperate with many other ... If your language lacks expressive features then you cannot write code ... memory management in comparison. ... Mostly because type errors mean that the programmer and compiler disagree ...
    (comp.programming)
  • Re: what is etymology? (linguistics and biology)
    ... Life and language, part 1, what is language? ... words in ancient Greek and in Latin). ... calamities, to face them directly when they occur, ...
    (sci.lang)
  • Re: A note on computing thugs and coding bums
    ... It would handle international characters if the execution character ... method I used in "Build Your Own .Net Language and Compiler". ... work areas and counting on Nul is an illusion. ...
    (comp.programming)