Re: static variable mayhem [message #11770 is a reply to message #11685] |
Wed, 13 May 1998 00:00  |
Martin Schultz
Messages: 515 Registered: August 1997
|
Senior Member |
|
|
Theo Brauers wrote:
>
> Hi:
>
> you may try the following:
>
> FUNCTION foo, x
> COMMON foo, called
> ; look if called is defined, what ever value it has!
> IF n_elements(called) EQ 0 THEN BEGIN
> ; define called
> called=1
> RETURN, x-1
> ENDIF
> RETURN, x+1
> END
>
> I hope it solves your problem.
> Theo
>
... but be careful when you want to assign variables of different length
to the common block (i.e. arrays or structures). Then you'll have to use
pointers, i.e.
commons,pinfo
if (n_elements(pinfo) eq 0) then pinfo=ptr_new()
if (ptr_valid(pinfo)) then *pinfo=data
------------------------------------------------------------ -------
Dr. Martin Schultz
Department for Earth&Planetary Sciences, Harvard University
109 Pierce Hall, 29 Oxford St., Cambridge, MA-02138, USA
phone: (617)-496-8318
fax : (617)-495-4551
e-mail: mgs@io.harvard.edu
Internet-homepage: http://www-as.harvard.edu/people/staff/mgs/
------------------------------------------------------------ -------
|
|
|