A couple of suggestions:
- use C++ instead of C and use static object.
The constructor for the static object will run when activation group is 
created and destructor will run when activation group is destroyed.
- another approach is to use Register Activation Group Exit Procedure 
(CEE4RAGE) API. The registered exit procedure will be called when 
activation group is destroyed.

always speaking only for myself

"We have all reasons to assume that our assumptions are not unreasonable."

"Boris" <bbresc512@xxxxxxxxxx> 
Sent by: c400-l-bounces+pytel=us.ibm.com@xxxxxxxxxxxx
05/29/2006 06:02 PM
Please respond to
C programming iSeries / AS400 <c400-l@xxxxxxxxxxxx>


[C400-L] Reading file basics

Hi all
I'm trying to write a function that opens a file, does some checking and 
returns to the main program. The problem is that the function is located 
a separate module and the main program is unaware of the file at all. All 
it's interested in is the result of the function. So it can't pass the 
as a parameter. On the other hand I don't want the function to open and 
close the file on every call. For example, here is my code in the 

_RIOFB_T *fb;
 _RFILE *infile;
if ( (infile = _Ropen("FILENAME", "rr")) == NULL ) {
  print_err("Can't open FILENAME file\n");
  return 0;
// some code here
return 1;

The first solution that came to my mind is to declare infile "static" and 
only open it once. It actually works, but then I don't know when to close 
the file, which is probably okay because the file will be closed when the 
main program finishes. I guess it's just not the correct programming.
It's actually a very small function, so I would want to create global 
variables and handle it with 2 more functions (one for open and another 
Are there any other ways?

Thanks in advance. 

This thread ...


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

This mailing list archive is Copyright 1997-2019 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].