Are the character digits ['0'..'9'] required to have contiguous numeric values?

前端 未结 1 1735
野的像风
野的像风 2020-12-03 21:16

Must a C++ implementation set the chars \'0\'-\'9\' to have contiguous numeric values, i.e. so that:

\'0\' -> 0+n
\'1\' -> 1+n
 m  -> m+n
\'9\' ->         


        
1条回答
  •  被撕碎了的回忆
    2020-12-03 21:25

    Indeed not looked hard enough: In 2.3. Character sets, item 3:

    In both the source and execution basic character sets, the value of each character after 0 in the above list of decimal digits shall be one greater than the value of the previous.

    And this is above list of decimal digits:

    0 1 2 3 4 5 6 7 8 9
    

    Therefore, an implementation must use a character set where the decimal digits have a contiguous representation. Thus, optimizations where you rely on this property are safe; however, optimizations where you rely on the coniguity of other digits (e.g. 'a'..'z') are not portable w.r.t. to the standard (see also header ). If you do this, make sure to assert that property.

    0 讨论(0)
提交回复
热议问题