Is this how the + operator is implemented in C?

后端 未结 9 1732
抹茶落季
抹茶落季 2021-01-30 06:21

When understanding how primitive operators such as +, -, * and / are implemented in C, I found the following snippet from an

9条回答
  •  无人共我
    2021-01-30 07:01

    To be pedantic, the C specification does not specify how addition is implemented.

    But to be realistic, the + operator on integer types smaller than or equal to the word size of your CPU get translated directly into an addition instruction for the CPU, and larger integer types get translated into multiple addition instructions with some extra bits to handle overflow.

    The CPU internally uses logic circuits to implement the addition, and does not use loops, bitshifts, or anything that has a close resemblance to how C works.

提交回复
热议问题