J
jacob navia
There was a recent thread about overflow handling. In that thread I
mentioned the two solutions that lcc-win proposes to detect overflow
efficiently.
(1) Direct handling of the overflow flag. This is risky and has some
drawbacks. Since C is not assembly, you can't be sure that some other
operation hidden within the C code modifies the flags. Besides, its
generalization is faulty since some machines integrate the overflow
handling into special versions of the four operations that trap
on overflow.
(2) The other option is just to pass a compile time argument to the
compiler that should call a function when oveerflows occurs. It
is the responsability of the compiler to figure out how to do that.
The only thing that you know is that a function will be called
telling you the source line and the file name of the place in
your code where overflow occurred. You can replace the default
function with a function of your own that does something else as
the default action, i.e. aborting the program. If your replacement
function returns, the code will go on exactly after the operation
that overflowed happened. The compiler saves all registers and
restores them after your function returns, oso the code will go on
with a random result.
The regulars here (kuyper, heathfield, thomson) started complaining that
the first solution "is not portable" without ever mentionig the second
solution. This message is intended to start a constructive discussion
so I would ask mr kuyper for instance, that says:
"I have learned to read as little as possible of what you write" that
they refrain from participating in the discussion to the benefit of his
blood pressure.
Thanks in advance.
mentioned the two solutions that lcc-win proposes to detect overflow
efficiently.
(1) Direct handling of the overflow flag. This is risky and has some
drawbacks. Since C is not assembly, you can't be sure that some other
operation hidden within the C code modifies the flags. Besides, its
generalization is faulty since some machines integrate the overflow
handling into special versions of the four operations that trap
on overflow.
(2) The other option is just to pass a compile time argument to the
compiler that should call a function when oveerflows occurs. It
is the responsability of the compiler to figure out how to do that.
The only thing that you know is that a function will be called
telling you the source line and the file name of the place in
your code where overflow occurred. You can replace the default
function with a function of your own that does something else as
the default action, i.e. aborting the program. If your replacement
function returns, the code will go on exactly after the operation
that overflowed happened. The compiler saves all registers and
restores them after your function returns, oso the code will go on
with a random result.
The regulars here (kuyper, heathfield, thomson) started complaining that
the first solution "is not portable" without ever mentionig the second
solution. This message is intended to start a constructive discussion
so I would ask mr kuyper for instance, that says:
"I have learned to read as little as possible of what you write" that
they refrain from participating in the discussion to the benefit of his
blood pressure.
Thanks in advance.