Are there any implementations that support a negative zero, or reserve it as a trap representation?

天涯浪子 提交于 2019-12-03 20:48:51
autistic

As brought to my attention by Iskar Jarak within the comments, the OS2200, which was most recently released in February of 2015, has an implementation of C known as UCS C, of which the manual documents

  • a conforming C implementation where-by "... CONFORMANCE/TWOSARITH is not used, negative zero is equivalent to zero in all 36-bit unsigned integer comparisons using less than (<), or equal (=). In unsigned comparisons using greater than (>), (236)-1 is greater than zero."
  • a questionably-conforming C implementation where-by "CONFORMANCE/TWOSARITH causes negative zero, (236)-1, to be considered a large unsigned integer by the generated code." As this violates several C standard clauses (6.2.6.2p2 stating "the sign bit has the value -(2M) (two's complement)" and "the sign bit has the value -(2M-1) (ones' complement)", 6.3.1.1p3 stating "The integer promotions preserve value including sign", in contradiction to the conversion to a large unsigned integer specified within the UCS/OS2200 doc) it follows that this could only conform if the negative zero bit pattern is treated as a trap representation, where-by undefined behaviour is invoked and so the constraints of the standard no longer apply.

In summary, ...

Are there any implementations that use this bit pattern for a negative zero or a trap representation?

Yes. The example provided can use this bit pattern for a negative zero or a trap representation, depending upon compiler conformance options.


For the follow-up questions 1&2, it follows that UCS C on OS2200 is an example of both of these.

As for question 3, to be answered another day... My time has come to end here :)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!