PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

system call always returns same non-zero value on Linux

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
glendening



Joined: 21 Dec 2004
Posts: 9

PostPosted: Mon Jan 10, 2005 9:39 pm    Post subject: system call always returns same non-zero value on Linux Reply with quote

On a Athlon box running RHEL3 Linux, I tried to use pgf90 on code which I'd previously used successfully with the g77 compiler and found that the "system" function returns the same non-zero number whether the call is successful or not. [VS g77 giving respective returns of 0 and 256 for successful and unsuccessful cases I tried). Is this a general result for Linux? [If so, it makes g77 a lot more useful than pgf90 in many cases.]
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6215
Location: The Portland Group Inc.

PostPosted: Tue Jan 11, 2005 4:34 pm    Post subject: Reply with quote

In fortran, when calling an external dummy procedure the compiler does not have access to this code and thus does not "know" what type the return value is. Instead it uses an implicit type base upon the name of the procedure being called. In this case, 'system' has an implicit type of 'REAL' and is why you getting wrong answers.

To fix this, explictily declare 'system' to be an integer.
Code:
      program test_system
      INTEGER IRV
      INTEGER system

      IRV = system('rm somefile')
      WRITE(*,*), "Return value is ", IRV
     
      end program test_system

Code:

% pgf90 test_system.f
% a.out
rm: cannot remove `somefile': No such file or directory
 Return value is           256
% echo "" > somefile
% a.out
 Return value is             0

g77 works because it's simply a fortran front end for gcc and lets gcc do the actual compilation.
Back to top
View user's profile
glendening



Joined: 21 Dec 2004
Posts: 9

PostPosted: Tue Jan 11, 2005 5:23 pm    Post subject: Reply with quote

Thanks for the explanation - I 'll remember that for other cases. It works and I'm glad I'll be able use pgf90 for my existing programs with some additional adjustments (having already adjusted them from EPC f90 to g77). I had read the PGF77 Reference Manual writeup on "system" and saw it described an an integer function and didn't realize I had to do more.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group