These lecture notes are based on chapter 3 in ``Programming Language Concepts and Paradigms'' by David Watt.
int x; /* static storage */
void main() {
int y; /* dynamic stack storage */
char *str; /* dynamic stack storage */
str = malloc(100); /* allocates 100 bytes of dynamic heap storage */
y = foo(23);
free(str); /* deallocates 100 bytes of dynamic heap storage */
} /* y and str deallocated as stack frame is popped */
int foo(int z) { /* z is dynamic stack storage */
char ch[100]; /* ch is dynamic stack storage */
if (z == 23) foo(7);
return 3; /* z and ch are deallocated as stack frame is popped,
3 put on top of stack */
}
/* C example */
char *str;
str = malloc(100); /* allocate 100 byte storage object in heap storage
put the pointer to it into str */
free(str); /* kill the allocated storage object */
/* C example */
char *str;
str = malloc(100); /* allocate 100 byte storage object in heap storage
put the pointer to it into str */
free(str); /* kill the allocated storage object */
*str = 'h'; /* str is now a dangling reference! attempt to put
the character 'h' to what is pointed at by str,
but str points to a dead object */
A persistent varible is a variable that lives beyond the execution of a program.
{ Pascal Example }
program curt(a_file_name) { a_file_name is a persistent file variable! }
....
end.
But why should files be different than other types of variables?
This is a violation of the type completeness principle.
Research is underway to add persistence to programming languages.