c++ - Where do local variables get stored at compile time? -


maybe i'm missing obvious, isn't during runtime local variables placed on stack when function containing variables gets called.

therefore when compiler step through our source code, place operations of function in .text segment, variables placed @ compile time can placed onto stack @ run-time? thanks

local variables aren't placed anywhere @ compile time.

the compiler generates code that, when executed @ run time, allocate space on stack (typically; other schemes possible). compiler records information each variable (name, type, size, offset relative stack pointer, etc.) , uses information generate code creates, accesses, , deallocates variable.

a technical digression: c doesn't have "local" , "global" variables, or @ least language standard doesn't use terms. object has lifetime (storage duration), span of time during execution when exists. more or less independently othat, object's name has scope, region of program text in name visible. variable declared inside function has block scope. has automatic storage duration default (meaning exists while containing block executing), has static storage duration if it's defined static keyword or if it's defined outside function. "local" static variable stored same way "global" variable, different way "local" automatic variable stored.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -