Re: in standard C it is impossible to write a correct program. Why?
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Wed, 02 Sep 2009 13:30:31 -0700
richard@xxxxxxxxxxxxxxx (Richard Tobin) writes:
In article <pan.2009.09.02.18.09.51.0@xxxxxxxxxxx>,
Nobody <nobody@xxxxxxxxxxx> wrote:
Does the lcc-win documentation provide sufficient information to determine
the last arithmetic operation performed when evaluating a particular
expression?
I would have thought it was far less ambiguous to provide a built-in
"function" (probably a macro):
check_overflow(expression)
which returns true if overflow occurs during the evaluation of the
expression. This doesn't require any odea of "last operation', makes
no assumption about overflow being indicated by a flag, and allows the
compiler to generate different (perhaps slower) code in cases where
overflow needs to be checked for.
For example:
if(check_overflow(c = a+b))
fprintf(stderr, "sorry, overflow in addition\n");
I'm trying to decide whether I like that better than my own
suggestion, which required specifying a bool lvalue into which to
store an indicator of whether the expression overflowed.
What we really want, I think, is something that yields two results,
the result of evaluating the expression and whether it overflowed.
With your proposal, the result of the expression is discarded, which
means it will almost always need to be an assignment.
Both have the advantage of keeping the information "local" in some
sense, rather than either querying some flag that's not obviously
associated with the expression or invoking a specified function.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- References:
- in standard C it is impossible to write a correct program. Why?
- From: io_x
- Re: in standard C it is impossible to write a correct program. Why?
- From: Nobody
- Re: in standard C it is impossible to write a correct program. Why?
- From: jacob navia
- Re: in standard C it is impossible to write a correct program. Why?
- From: Nobody
- Re: in standard C it is impossible to write a correct program. Why?
- From: Richard Tobin
- in standard C it is impossible to write a correct program. Why?
- Prev by Date: Re: in standard C it is impossible to write a correct program. Why?
- Next by Date: Re: Lcc win overflow handling
- Previous by thread: Re: in standard C it is impossible to write a correct program. Why?
- Next by thread: Re: in standard C it is impossible to write a correct program. Why?
- Index(es):
Relevant Pages
|