char and the usual arithmetic conversion rules

后端 未结 5 882
一向
一向 2020-12-10 17:00

I know this question has been asked and seemingly answered a gazillion times over but I can\'t seem to match the answers to my own experience.

The C standard specifi

5条回答
  •  心在旅途
    2020-12-10 17:45

    In 6.3.1.8 (usual arithmetic conversions, n1570), we can read

    Otherwise, the integer promotions are performed on both operands. Then the following rules are applied to the promoted operands:

    so integer promotion is part of the usual arithmetic conversions for integer types.

    Thus in the abstratc machine, the conversion to (unsigned) int must be done.

    But by the "as if" rule, if the behaviour is indistinguishable from that by strictly implementing the abstract machine, the implementation may do things differently.

    So if it is guaranteed that the computation using only single bytes has the same result as the computation promoting to int, the implementation is allowed to use single-byte arithmetic.

提交回复
热议问题