|
Ahh, yes, I see. You are using the static variable as a state variable. I have done this kind of things in other programs, and I've always found it best to be able to call the procedure with a reset variable to initialize things when I wanted them to. Something like alwaysfalse('Reset') if alwaystrue AND alwaysfalse('') and alwaysfalse('') although this is not that clean. Something else I would do would be to use a global variable instead of passing something as a parameter. Such as: GL_Reset = TRUE if alwaystrue AND alwaysfalse AND alwaysfalse then have alwaysfalse do something like: if GL_Reset = TRUE (or Parm(1) = 'Reset') GL_Reset = FALSE ST_BeenHere = FALSE EndIf but this comes from my paranoia of not expecting any compiler to initialize my variables correctly if at all. I would initialize them in code. I think what you are trying to do is a viable and meaningful use of static variables, and in your particular case I agree, this is an undesirable side effect in this case that has to be worked around. Just a curiosity question, but are there Global Static variables? By definition Global Variables generally are static. That would be useful in this case. GL_BeenHere = FALSE if alwaystrue AND alwaysfalse AND alwaysfalse Regards, Jim Langston Joel Fritz wrote: > > If I compile a program actgrp *caller and run it in the default activation > group, the static variable's lifetime is the job. This leads to what I > thought of as unexpected results. > > The particular thing I was doing was using a static variable as a flag to > differentiate between the first call and succeeding calls to a procedure > defined in the main program. I know there's other ways to do it; it just > seemed like a reasonable thing to do. > > I wrote a simple program to demonstrate short circuit evaluation of things > ANDed together and wrote a procedure that always returned false. It had a > static counter that was incremented each time the procedure was called. If > the counter was greater than 1 the procedure wrote a line to a print file. > > I called the procedure like this: > > if alwaystrue AND alwaysfalse AND alwaysfalse > > The print file will have the line from alwaysfalse only if it's executed a > second time. Works as expected the first time, not the way I expected the > second time. I know better now. > > > -----Original Message----- > > From: Jim Langston [mailto:jimlangston@conexfreight.com] > > Sent: Wednesday, November 15, 2000 8:20 AM > > To: RPG400-L@midrange.com > > Subject: Re: lifetime of a static variable > > > > > > 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 > > > +--- > | 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 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.