Tim Rentsch <> writes:
> pete <> writes:
>> Tim Rentsch wrote:
>>> Keith Thompson <kst-> writes:
[...]
>>>>I think -0 can be a trap representation, but if it is it can't be the
>>>>result of a conversion of a valid value.
>>>
>>> Of course it can. The implementation-defined signal produced
>>> by the out-of-range conversion can produce whatever representation
>>> it wants to.
>>
>> INTERNATIONAL STANDARD
>> ISO/IEC 9899
>>
>> 6.2.6.2 Integer types
>>
>> 3 If the implementation supports negative zeros,
>> they shall be generated only by:
>> * the &, |, ^, ~, <<, and >> operators with arguments that
>> produce such a value;
>> * the +, -, *, /, and % operators where one argument is a
>> negative zero and the result is zero;
>> * compound assignment operators based on the above cases.
>
> Right, but an out-of-range value is being converted:
>
> 6.3.1.3 Signed and unsigned integers
>
> 3 Otherwise, the new type is signed and the value cannot be
> represented in it; either the result is implementation-defined
> or an implementation-defined signal is raised.
>
> The implementation-supplied signal handler for this signal is
> free to use &, |, etc, to generate a result for the conversion.
> Remember the semantics of default signal handlers are
> implementation-defined.
A user-written signal handler can't have the visibility necessary to
generate a result for the conversion. I'm not convinced that an
implementation-defined signal handler can do so either, unless by
taking advantage of undefined behavior.
But (C99 7.14.1.1p3):
If and when the function [the signal handler] returns, if
the value of sig is SIGFPE, SIGILL, SIGSEGV, or any other
implementation-defined value corresponding to a computational
exception [presumably this includes overflow on a signed integer
conversion], the behavior is undefined; otherwise the program
will resume execution at the point it was interrupted.
So if the particular undefined behavior of the implementation-defined
signal handler involves causing the conversion to yield a trap
representation, then yes, a trap representation can result from a
conversion.
It doesn't seem terribly likely, though.
--
Keith Thompson (The_Other_Keith)
kst- <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"