| View previous topic :: View next topic |
| Author |
Message |
glendening
Joined: 21 Dec 2004 Posts: 9
|
Posted: Mon Jan 10, 2005 9:39 pm Post subject: system call always returns same non-zero value on Linux |
|
|
| 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 |
|
 |
mkcolg
Joined: 30 Jun 2004 Posts: 4996 Location: The Portland Group Inc.
|
Posted: Tue Jan 11, 2005 4:34 pm Post subject: |
|
|
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 |
|
 |
glendening
Joined: 21 Dec 2004 Posts: 9
|
Posted: Tue Jan 11, 2005 5:23 pm Post subject: |
|
|
| 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 |
|
 |
|