Flex on MSDOS and C block structure

Henry Spencer henry at utzoo.uucp
Sun May 15 10:21:27 AEST 1988


>  ...  Does the ANSI standard (or
>  K&R for that matter) have anything to say about exiting a context and
>  reentering it saving (or not saving) the state of local variables?

All definitions of C that I'm aware of make it quite clear that the values
of uninitialized local variables are unknown when the block containing
them is entered, *regardless* of whether the block was executed before and
gave them a value then.  Old values go away when the block is exited.

> Might
>   the fact that this code seems to work almost everywhere imply that Unix
>   and VMS (AT&T derived?) C compilers allocate local variables on the
>   entry to the function, rather than entry to the block?...

Correct in general.  But it's not something one should depend on, of course.
Even if allocation is at function-entry time, clever compilers may well
re-use the space for something else after the block is exited.
-- 
NASA is to spaceflight as            |  Henry Spencer @ U of Toronto Zoology
the Post Office is to mail.          | {ihnp4,decvax,uunet!mnetor}!utzoo!henry



More information about the Comp.lang.c mailing list