ch := make(chan int, 10)
fmt.Println(cap(ch))
is function call cap(ch)
constant or evaluated?
golang spec said:
The expression len(s) is constant if s is a string constant. The expressions len(s) and cap(s) are constants if the type of s is an array or pointer to an array and the expression s does not contain channel receives or (non-constant) function calls; in this case s is not evaluated. Otherwise, invocations of len and cap are not constant and s is evaluated.
seems that is evaluated.
Yes, cap()
is not constant when applied to a channel, as the capacity of a channel isn't encoded in the type and thus not known at compile time.
Sure call cap(ch) evaluated, just because of
ch := make(chan int, 10)
fmt.Println(cap(ch))
ch = make(chan int, 9)
fmt.Println(cap(ch))
Proof-link https://play.golang.org/p/R0TfCpC-4L