× 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: Joel Fritz <JFritz@xxxxxxxxxxxxxxxx>
  • Date: Wed, 15 Nov 2000 16:40:01 -0800

This has been highly educational for me.  I've placed some comments in line.


> -----Original Message-----
> From: bmorris@ca.ibm.com [mailto:bmorris@ca.ibm.com]
> Sent: Wednesday, November 15, 2000 1:15 PM
> To: RPG400-L@midrange.com
> Subject: RE: lifetime of a static variable
> 
> 
> 
> >Date: Wed, 15 Nov 2000 08:54:28 -0800
> >From: Joel Fritz <JFritz@sharperimage.com>
> >
> >I'm willing to accept that that's the way it works and code 
> accordingly.
> >I'm curious why it was designed that way.  I guess I think 
> of a static
> >variable's lifetime in terms of the way I learned about them 
> in C on the
> PC
> >nearly 10 years ago.  Once the main program ended, all 
> _properly managed_
> >memory was returned to the operating system and the static variable
> started
> >with its initialized value at each call to the main program.
> 
> Joel, the default for CRTPGM is *NEW just so that C programs 
> written with
> that assumption would port easily to the AS/400.  In the PC 
> environment,
> was it even possible to have static storage retained across calls?

So that's why the default is *NEW.  AFAIK, static storage isn't retained
across calls on the PC.  



> 
> I think what you're suggesting is that when a _module_'s (not program)
> main procedure returns with LR on, when that main procedure 
> gets called
> again, the subprocedure static should get reinitialized along with the
> other globals in the module. 

That was what I was used to seeing.

> Maybe that would have been the right
> behaviour, maybe not.  What about calls to the subprocedures between
> calls to the main procedure?  Should the subprocedures be 
> reinitialized
> even before the main procedure gets called again?

No.  
> 
> As to whether this is right or wrong, maybe it would have 
> been better to
> have different behaviour for subprocedures in a module with a 
> main.  Maybe
> the subprocedures' static should have been subject to LR 
> reinitialization.
> Or at least non-exported subprocedures.  But then there would 
> have been
> different behaviour for a subprocedure in a NOMAIN module.

The NOMAIN case is something I'm not so sure about.  I always thought of a
NOMAIN module as something equivalent to what's called object code on the PC
that becomes part of an executable through what I assumed where different
names for the same thing, binding or linking.  Based on my experience, I'd
expect the lifetime rule to be the same  for subprocedures declared in a
NOMAIN module bound by copy.  Not so sure about binding by reference.  I'll
bet I don't understand binding correctly either. <g>
  
> Our thinking
> was that subprocedures are more ILE-ish than RPG-ish, and 
> should behave
> like ILE things, and not be subject to the RPG cycle.

I've never used the cycle and don't understand it well enough to comment.
That probably contributes to my confusion.  

> 
> By the way, EXPORT fields behave the same way as subprocedure static
> fields.
> They only get initialized once, independent of LR.
> 
> Barbara Morris
> 
> 
+---
| 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 ...


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.