← Back to context

Comment by umanwizard

5 hours ago

> making basic types work differently from C would involve major performance costs.

Not if you compile with optimizations on. This C code:

  int wrapping_add_ints(int x, int y) {
      return (int)((unsigned)x + (unsigned)y);
  }

Compiles to this x86-64 assembly (with clang -O2):

  wrapping_add_ints:
          lea     eax, [rdi + rsi]
          ret

Which, for those who aren't familiar with x86 assembly, is just the normal instruction for adding two numbers with wrapping semantics.