|
|
|
|
|
by mikepurvis
1590 days ago
|
|
Isn't that an implementation choice? Like in C++, a const is absolutely allocated since you can get a pointer to one. And then you can do horrible stuff like const_cast that pointer and mutate the value, and the possibility of that occurring prevents the compiler from doing certain const-related optimizations. |
|
If I understand you correctly, you claim you can get a pointer to a Go const. This is not the case. For example, the following code will not compile:
const a int = 1
var b *int = &a
./prog.go:5:15: cannot take the address of a
See https://go.dev/play/p/QPxP-tF6qIs for a live example.