Skip to content

proposal: Go 2: Add checked/unchecked arithmetic keywords #29472

Closed
@firelizzard18

Description

@firelizzard18

I propose that Go adds checked and unchecked keywords for arithmetic operations that function like those of C#. This is somewhat similar to the Go 2 error handling proposal.

This is related to #19624. If #19624 is accepted, then cases like hash64.go could be handled by wrapping the calculations in an unchecked block, which is a cleaner solution than anything I saw presented on #19624.

Blocks

checked {
  x := a * b
  y := a + b
  z := x^y
}

unchecked {
  x := a * b
  y := a + b
  z := x^y
}

Statements

It would be difficult to allow checked and unchecked to be used on statements without breaking backwards compatibility or making it confusing. The possibilities that occur to me are A) not bothering (only supporting blocks), B) unchecked(a * b), or C) unchecked a * b.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions