It is common for bare-metal systems to allocate variables statically. The golang is trying to be smart with how it allocates memory (stack/heap). You can also declare a variable statically, but it will have to be declared at a package scope.
Suggestion here is to introduce new keywords (extending the Go language spec):
static: force allocation on the BSS (statically)
stack: force allocation on the stack (even if it the compiler can't determine whether it is safe)
E.g.:
static v1 := f() // v1 will always be allocated on the BSS
static var v2 [10]int64 // v2 will be allocated statically with the slice size of 10
static var v3 []int64 // possibly a compile error, slize size is zero and can't grow because it is forced to be static
stack v2 := f() // v4 will always be allocated on the stack
stack var v5 int64 // v5 will be allocated on the stack
It is common for bare-metal systems to allocate variables statically. The golang is trying to be smart with how it allocates memory (stack/heap). You can also declare a variable statically, but it will have to be declared at a package scope.
Suggestion here is to introduce new keywords (extending the Go language spec):
static: force allocation on the BSS (statically)stack: force allocation on the stack (even if it the compiler can't determine whether it is safe)E.g.: