| Re: Static Variables in IDL [message #5997 is a reply to message #5924] |
Thu, 14 March 1996 00:00  |
santanu
Messages: 8 Registered: March 1996
|
Junior Member |
|
|
rivers@cars3.uchicago.edu (Mark Rivers) writes:
> In article <4i7ara$606@vixen.cso.uiuc.edu>, santanu@ux7.cso.uiuc.edu (Santanu Bhattacharyya) writes:
>> Hi,
>> Is there a way to statically allocate variables in IDL ? I would
>> like to define a static variable in a .pro which is repeatedly called
>> from an upper level. I am specifically looking for the IDL counterpart
>> of
>> static int testint;
>>
> Yes, it is easy. Use a common block. Make the name of the common block unique
> enough that you can be sure it won't conflict with common blocks used in other
> procedures.
> common unique_name, testint
> testint = 14
Pardon me if I appear a bit obtuse, but I am still a little confused. I am
under the impression that the common block declaration is equivalent to
C's global declaration. What I would like to have is a bit of non re-entrant
code in a standalone function (.pro). I want an IDL .pro that does the
following::
main()
{
for(;;) non_rEntrant();
}
non_rEntrant()
{
static int block=1;
if (block == 1){
puts("This is executed only once");
block=0;
}
puts("And this is done over and over again");
}
The following does exactly the same thing ----------------
pro test
common SHARE,block
block=1
repeat begin
call_procedure,'non_rEntrant'
endrep until block eq 1
end
pro non_rEntrant
common SHARE,block
if block eq 1 then begin print,'This is executed only once' & block=0 & endif
print,'And this is done over and over again'
end
But the two lower level function/pro's are not the same, the
C version is standalone, how do I make the IDL pro non_rEntrant behave
in the same way ?
I really appreciate the help,
Thanks,
Santanu
santanu@uiuc.edu
> testint will have the value 14 the next time the .pro file is called.
> ____________________________________________________________
> Mark Rivers (312) 702-2279 (office)
> CARS (312) 702-9951 (secretary)
> Univ. of Chicago (312) 702-5454 (FAX)
> 5640 S. Ellis Ave. (708) 922-0499 (home)
> Chicago, IL 60637 rivers@cars3.uchicago.edu (Internet)
|
|
|
|