× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: lifetime of a static variable
  • From: Jim Langston <jimlangston@xxxxxxxxxxxxxxxx>
  • Date: Wed, 15 Nov 2000 08:20:27 -0800
  • Organization: Pacer International

If you don't want static variables to retain their values during the
lifetime of the activation group, just what are you using them for?

Otherwise, just use "normal" variables.

Regards,

Jim Langston

Joel Fritz wrote:
> 
> What is the lifetime of a a local static variable?
> 
> I wrote a little test program that included a static variable defined in a
> sub procedure.  It was supposed to distinguish between the first and second
> call to the procedure within the test program.  My test was static varible >
> 0.  Worked as expected on the first call of the program.  On the second call
> of the program the variable retained its value from the first call.
> 
> Then I got interested.  I wrote a program that printed the value of a static
> variable defined in a sub procedure.  The sub procedure added 1 to the value
> of the static variable and returned that value.  The main program printed
> the value of the variable assigned the value of the procedure--i.e. eval x =
> staticvarproc, then print the value of x.
> 
> On the first call to the main program, the output is 1, on the second call
> 2, and so forth.
> 
> The program ends with last record *on and was compiled activation group
> *caller.  I called it from the command line repeatedly.  It seems to me that
> the lifetime of the variable is the lifetime of the activation group since
> when I sign off and call the program after signing on again, the value goes
> back to 1 for the first call.
> 
> Is this the way it ought to work?  Seems like static local variables
> shouldn't outlive the programs to which they are local when the program ends
> with lr on.
> +---
> | This is the RPG/400 Mailing List!
> | To submit a new message, send your mail to RPG400-L@midrange.com.
> | To subscribe to this list send email to RPG400-L-SUB@midrange.com.
> | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
> | Questions should be directed to the list owner/operator: david@midrange.com
> +---
+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.