What's the reason high-level languages like C#/Java mask the bit shift count operand?

后端 未结 3 1610
鱼传尺愫
鱼传尺愫 2020-12-09 17:42

This is more of a language design rather than a programming question.

The following is an excerpt from JLS 15.19 Shift Operators:

If the promoted

3条回答
  •  醉话见心
    2020-12-09 18:10

    Java and C# are not fully "high-level". They try real hard to be such that they can be compiled into efficient code, in order to shine in micro-benchmarks. This is why they have the "value types" such as int instead of having, as default integer type, true integers, which would be objects in their own right, and not limited to a fixed range.

    Hence, they mimic what the hardware does. They trim it a bit, in that they mandate masking, whereas C only allows it. Still, Java and C# are "medium-level" languages.

提交回复
热议问题