Next: Program structure Up: How automatic variables Previous: Recursion

A warning

C allows you to make copies of addresses. If you write a routine which returns the address of an automatic created within the routine, then the result is unpredictable because that item is no longer on the stack. This can cause very confusing errors, because it might well work (the memory and its contents are still there of course). It depends whether that part of the stack memory has been re-used, for example if interpose another function call before looking at what the item pointed to contains. Therefore, never pass addresses of locally-created items to outside the containing block. This kind of problem cannot occur in a pure functional language because you never deal with memory locations or addresses.



Next: Program structure Up: How automatic variables Previous: Recursion


maspjw@
Tue Sep 27 15:29:34 BST 1994