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

explicit runtime condition code checking, particularly overflow

5 views
Skip to first unread message

Thomas Purcell

unread,
Dec 2, 1987, 4:03:31 PM12/2/87
to

I'd love to know if there's ANY way of doing runtime condition code checking
in C. In particular, I'd like to know if there's any way to write a line of
C code which essentially translates into a Branch On Overflow, or Bcc LABEL,
where B means branch, cc is a condition code, and label is the name of a
procedure.

Kernighan and Ritchie I think say something like 'there should be a library
routine to deal with it, depending on your machine'. My other two C
manuals, (Thom Hogan, and the other by Steve Kochan) don't seem to mention
the problem at all. [perhaps I missed a mention of it]

All I want to do is see if an expression which I'm evaluating overflows, and
handle it myself if it does! And the only answer I've gotten so far is
on the order of "random machine action on overflow depending on
implementation." Can anybody help?

Please send a copy of your response directly.

-thomas
en...@crnlvax1.bitnet The symbol after the "vax" is a ONE, not
en...@vax1.ccs.cornell.edu an L .

Doug Gwyn

unread,
Dec 2, 1987, 6:58:43 PM12/2/87
to
In article <5...@vax1.UUCP> en...@vax1.ccs.cornell.edu writes:
>In particular, I'd like to know if there's any way to write a line of
>C code which essentially translates into a Branch On Overflow, or Bcc LABEL,
>where B means branch, cc is a condition code, and label is the name of a
>procedure.

No, and the main reason is that C is at a higher level than that.
A single C expression may involve possible setting of the condition
codes several times during evaluation, and due to optimization you
can't normally even be sure what code will be generated; for example
it may depend on whether there are any free scratch registers
available, which in turn is affected by global aspects of the code.

If your hardware generates (or can be asked to generate) traps on
arithmetic exceptions, then there is a chance you can detect some
kinds of "overflow". For example, a floating-point division by
zero often results in a SIGFPE being sent to your process, and you
can set up a signal handler in advance to field SIGFPE and take
some appropriate action (normally a longjmp()). However, beware
that the C implementation may be assuming certain things about the
runtime environment, notably that integer overflow does not cause
a trap, and changing such aspects of your environment can break
the code that the compiler generates. (Someone actually did that
once here -- he turned on floating-point overflow trapping on our
Gould PowerNodes, not realizing that due to a silly design defect
that it also enabled integer arithmetic exception traps.)

Paul Czarnecki

unread,
Dec 16, 1987, 11:06:22 PM12/16/87
to
In article <5...@vax1.UUCP> en...@vax1.ccs.cornell.edu writes:
>
>I'd love to know if there's ANY way of doing runtime condition code checking
>in C. In particular, I'd like to know if there's any way to write a line of
>C code which essentially translates into a Branch On Overflow, or Bcc LABEL,
>where B means branch, cc is a condition code, and label is the name of a
>procedure.

The more general case of runtime and type checking is handled by line
of "Safe C" products by Catalytix (617-497-2160). Your particular
"Bcc Label" example is not even close to what they do. Contact them
for further information. It may be good enough for you.

DISCLAIMER: I used to have some business and personal ties with
Catalytix. Both have lapsed.

>Please send a copy of your response directly.

>en...@crnlvax1.bitnet

Sorry, bitnet? what's that? :-)

pZ


--
Paul Czarnecki -- Spam, spam, spam, Usenet, and spam
{{harvard,ll-xn}!adelie,{decvax,allegra,talcott}!encore}!munsell!pz

0 new messages