May 18, 2019

[Go] Max compile time intermediate const integer in x86_go_gc compiler :-)

package main

import (
 "fmt"
)

const large = 1 << 511 // max
const back = large >> 510

func main() {
 fmt.Println(back)
}

Go's constness is well defined/designed to contain boolean constants, rune constants, integer constants, floating-point constants, complex constants, and string constants.
Spec:
https://golang.org/ref/spec#Constants
Rob Pike explained:
https://blog.golang.org/constants

C++'s constexpr contains only LiteralType due to historical reason/backward compatibility with C:
https://en.cppreference.com/w/cpp/named_req/LiteralType

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.