
www.Usenet.com
| <-- __Chronological__ --> | <-- __Thread__ --> |
"John R. Strohm" <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]:
>> > Not if the compiler can determine that they're no longer needed after
>> > some point in program flow. They must behave *as if* they persisted
>> > for the duration of the program --- but if the program doesn't look,
>> > the compiler is allowed to re-use the space otherwise.
>>
>> I'd like to know if you have an example of such a condition as I'm
>> having a hard time seeing how a compiler could know that it will swap
>> out a function for use by another. Maybe I'm too used to Harvard
>> architectures.
>
> Observe.
>
> static int switch = 0;
> static int x;
> static int y;
>
> void test(void){
> if (switch == 0) {
> do a whole bunch of stuff with x
> if (some interesting case) {
> switch = 1;
> }
> do a bunch of stuff with y;
> } else {
> do a bunch of other stuff with y;
> }
> }
>
> Observe that the switch initially points to x, and the program uses x.
> Once the switch is thrown to y, the program only uses y, and NEVER AGAIN
> TOUCHES X. A sufficiently-advanced compiler could, in principle, notice
> that x and y have disjoint lifetimes, and use the same storage location
> for the two variables.
First, you can't have a variable names 'switch' since this is a keyword.
Second, I was asking about static not not having program duration for a
function, not a variable.
Thanks.
--
- Mark ->
--
| <-- __Chronological__ --> | <-- __Thread__ --> |