Static (i.e. const something) variables are at least in effect put on the heap when their declaration is first encountered. From that point onwards their value is retained, but they're only visible inside the function where they're declared even though their scope could be considered as similar to globals.
Interesting, since the initial value is known, I assume it is compiled into the executable file. I’m curious How is the initial value stored within the exe so that it can be used? Also is declaration first encountered when the code execution calls the procedure that the static constant is in?
How that works might, in practice, be implementation-defined. However it's reasonable to assume that if it's a simple numeric it will show up in the assembler output (i.e. which you could look at if so inclined :-) while if it's a more complex data structure it will be in one of the initialised sections of the relevant object file (.obj, .o etc. depending on the toolchain) hence in an initialised group of the executable (.exe or ELF, again depending on the toolchain and OS) and it will be later copied into working storage.
"Static constant"... horrid terminology, I believe we've got Turbo Pascal to blame for that. In any event it was omitted from Wirth's Pascal even though present (as "own" variables) in ALGOL-60, and that was one of the things on Kernighan's "why I hate Pascal" list.
Anyway, going back to where we were: I /think/ that it's copied onto the heap when encountered in a function (i.e. doesn't occupy space unless used), but it could be equally initialised by the compiler itself... the latter case would potentially reduce the risk of memory fragmentation. PascalDragon could obviously set us right there.
That might be fairly easily tested: define a large static data structure in a function, and check the size of the heap before and after using it.
However the thing that really matters is that in Pascal (and Rust), even if something is "in scope" if considered in the context of stack frames, the compiler does not necessarily permit it to be accessed i.e. "make it visible"... /unless/ of course you decide to try something clever by messing with pointers which is rarely a good idea. C doesn't usually distinguish between scope and visibility (and encourages pointer abuse), which is why the improvements in Rust are causing a stir.
Cowgol is interesting: it's designed for small (very small) computers and the compiler allocates /everything/ into heaplike storage without using a stack: in short it's like Rust but more so. That sacrifices recursion, which was of course one of the selling points of ALGOL when compared with FORTRAN; however (a) it's rare to even consider recursion in resource-limited systems and (b) compiler technology has improved a lot since the mid-50s.
MarkMLl