Re: static variable mayhem [message #11682] |
Tue, 12 May 1998 00:00  |
wmc
Messages: 117 Registered: February 1995
|
Senior Member |
|
|
In article 1@filet.nrlssc.navy.mil, "T Bowers" <tbowers@nrlssc.navy.mil> writes:
> function foofunc, x
> common CBlock, firstTimeInFooFunc ;I think this'll init to 0
>
> if (NOT firstTimeInFooFunc) then begin ;init'd to 0, so I'll just NOT
> the bastard
> firstTimeInFooFunc = 1 ;Set so this'll never happen again on subsequent
> calls
> return, x = x - 1
> endif $
> ....
>
> No such luck. It compiles, but when I single step to this line, I get
> % Variable is undefined: FIRSTTIMEINFOOFUNC (CBLOCK).
> % Execution halted at: FOOFUNC blah, blah, blah
Well I don't think it compiles, since return,x=x-1 is odd.
But if you swap that to return,x-1 then it should compile.
To make it *work*, say
common CBlock...
at the main prompt (or somewhere above foofunc) and then say
first...func=0 (or 1, or whatever you want...)
Then it will do what you want. Ugly, though.
- William
---
William M Connolley | wmc@bas.ac.uk | http://www.nbs.ac.uk/public/icd/wmc/
Climate Modeller, British Antarctic Survey | Disclaimer: I speak for myself
|
|
|