I come from a background in Pascal, where there is no "automatic duration", unless you want to count function data variables that are pushed onto the stack when the function is called. Static duration would mean that global variables, like in an asm program, are thrown in a part of the actual .exe, whether initialized or not.
I'm confused about the meaning of automatic duration in C++. Are the variables actually allocated at runtime? Would that be on the heap or on the stack? I understand that global variables are static the entire program, so I assume they are defined at compile time. I also understand that within any block, variables are either dynamic or automatic duration; meaning that main() itself uses variables that are auto. Does this mean that if I write:
char myStr[] = "abcdefghijklmnopqrstuvwxyz";
in main, or another block, that first space is made on the stack for myStr, and then that string is copied to the stack? As opposed to storing the string at compile-time and pointing myStr to it? Wouldn't this have efficiency draw backs? Or am I misunderstanding the meaning of it?
Thanks for clarifying!



LinkBack URL
About LinkBacks


