home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.sgi
- Path: sparky!uunet!munnari.oz.au!mips!mips!odin!bananapc.csd.sgi.com!ciemo
- From: ciemo@bananapc.csd.sgi.com (Dave Ciemiewicz)
- Subject: Re: Problem with "chdir"
- Message-ID: <1992Aug31.194941.25918@odin.corp.sgi.com>
- Sender: news@odin.corp.sgi.com (Net News)
- Nntp-Posting-Host: bananapc.csd.sgi.com
- Organization: Silicon Graphics, Customer Support Division
- References: <1992Aug31.161656.1@vaxa.strath.ac.uk>
- Date: Mon, 31 Aug 1992 19:49:41 GMT
- Lines: 51
-
- In article <1992Aug31.161656.1@vaxa.strath.ac.uk>, cbas25@vaxa.strath.ac.uk writes:
- |> C-------------------------------cut here------------------------
- |> PROGRAM CHANGEDIR
- |>
- |> C To test the fortran subroutine chdir
- |> I = 999
- |> write (*,*) I
- |> I = chdir ('notthere') ! This directory is not there
- |> write (*,*) I ! Should return -1
- |> call system ('pwd') ! No change in directory
- |> I = chdir ('..') ! Go to parent directory
- |> write (*,*) I ! Should return 0
- |> call system ('pwd') ! Should now be parent directory
- |> stop
- |> end
- |> C-------------------------------cut here------------------------
- |>
-
- The problem with above program is that you have not declared the chdir
- function as one which returns INTEGER*4. Using Fortran's intrinsic
- typing rules, it f77 will assume that chdir is REAL, not INTEGER*4 thus
- you get bogus answers. If you change the code to:
-
- PROGRAM CHANGEDIR
-
- EXTERNAL CHDIR
- INTEGER*4 CHDIR
-
- ...
-
- I = chdir('notthere')
-
- the example will work correctly:
-
- bananapc 1807$ chdir
- 999
- -1
- /disk2/tmp/hypot
- 0
- /disk2/tmp
-
- No bug in the compiler under 4.0.x. In fact, it was a bug in the old versions
- of the compiler if it ever worked without specifying INTEGER*4 CHDIR.
-
- --
-
- __ * __ _ __ ___
- / \ / / / / \/ \/ \ He was a man like any other man, however, not
- / / \/ / /\ / / quite like any other man.
- \___/\__/\_/ /_/ / \__/
- *
-