gfortran (v4.0) redirected output `feature'?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

gfortran (v4.0) redirected output `feature'?

Juan Gallego

greetings all,

i'm trying to build ATLAS (3.7.10) with GCC 4.0, and i've hit a peculiar
`feature': during the configuration phase, ATLAS complains that it
can not determine the fortran naming conventions.  after some careful
digging, i've found the problem (which seems rather strange, at least
for me).

consider these 2 files (taken directly from ATLAS):

--- begin fname.f ---
*
      PROGRAM NAMTST
      EXTERNAL C_ROUTINE
*
      CALL C_ROUTINE()
*
      STOP
      END
--- end ---

and

--- begin cname.c ---

#include <stdio.h>
void c_routine_(void)  { printf("-DAdd_\n"); }
void c_routine(void)   { printf("-DNoChange\n"); }
void C_ROUTINE(void)  { printf("-DUpCase\n"); }
void c_routine__(void) { printf("-DAdd__\n"); }

--- end ---

compiled respectively with (leading `> ' is the prompt):

> gfortran -c fname.f

and

> cc -c cname.c

and linked with:

> gfortran -o ./xfcnam fname.o cname.o

i run the executable:

> ./xfcnam
-DAdd__
STOP 0

as expected. but if stdout is redirected to a file, c_routine's output
disappears:
 
> ./xfcnam > t
STOP 0
> cat t
> ls -l t
-rw-r--r--    1 juan     users           0 Jun 21 13:47 t

same thing if the output is piped to another command (say cat).

if i modify fname.c to call ABORT() after calling c_routine, c_routine's
output (redirected or not) survives:

> ./xfcnam.abort > t
> cat t
-DAdd__
> ls -l t
-rw-r--r--    1 juan     users           8 Jun 21 13:51 t

so gfortran seems to be destroying/mangling the output stream on exit.

is this `feature' part of the standard (alas, i'm F90/F95 illiterate)? is it
gfortran specific? is this an ATLAS abuse of the language? or it isn't a
`feature' at all, but a bug?

i've googled and perused the ml archives, but i haven't found anything
relevant (or my searching leaves much to be desired).

any insight/suggestion/comment/anything?

many tia,
--
juan
Reply | Threaded
Open this post in threaded view
|

Re: gfortran (v4.0) redirected output `feature'?

Steve Kargl
On Tue, Jun 21, 2005 at 02:06:15PM -0400, Juan Gallego wrote:
>
>
> as expected. but if stdout is redirected to a file, c_routine's output
> disappears:
>  
> > ./xfcnam > t
> STOP 0
> > cat t

PR libfortran/20179

This has been fixed at least in cvs mainline.  The patch may have
been applied to the 4.0 branch, but I'm not in a position to
investigate any further.

--
Steve
Reply | Threaded
Open this post in threaded view
|

Re: gfortran (v4.0) redirected output `feature'?

Juan Gallego
On 2005-06-21 11:30-0700, Steve Kargl <[hidden email]> wrote:

| On Tue, Jun 21, 2005 at 02:06:15PM -0400, Juan Gallego wrote:
| >
| >
| > as expected. but if stdout is redirected to a file, c_routine's output
| > disappears:
| >  
| > > ./xfcnam > t
| > STOP 0
| > > cat t
|
| PR libfortran/20179
|
| This has been fixed at least in cvs mainline.  The patch may have
| been applied to the 4.0 branch, but I'm not in a position to
| investigate any further.

hi Steve,

many many thanks. adding the fflush calls to the c_routines does indeed fix
the problem. i'll try the patch and rebuild gfortran see if that's enough.

--
juan
Reply | Threaded
Open this post in threaded view
|

Re: gfortran (v4.0) redirected output `feature'?

Steve Kargl
On Tue, Jun 21, 2005 at 03:30:58PM -0400, Juan Gallego wrote:

> On 2005-06-21 11:30-0700, Steve Kargl <[hidden email]> wrote:
>
> | On Tue, Jun 21, 2005 at 02:06:15PM -0400, Juan Gallego wrote:
> | >
> | >
> | > as expected. but if stdout is redirected to a file, c_routine's output
> | > disappears:
> | >  
> | > > ./xfcnam > t
> | > STOP 0
> | > > cat t
> |
> | PR libfortran/20179
> |
> | This has been fixed at least in cvs mainline.  The patch may have
> | been applied to the 4.0 branch, but I'm not in a position to
> | investigate any further.
>
> many many thanks. adding the fflush calls to the c_routines does indeed fix
> the problem. i'll try the patch and rebuild gfortran see if that's enough.
>

There is a release candidate for gcc 4.0.1.  I don't
have the URL handy, but the patch has been applied to
the 4.0 branch and should be in 4.0.1.  Hunt around
gcc.gnu.org for a gcc-4.0.1.

--
Steve
Reply | Threaded
Open this post in threaded view
|

Re: gfortran (v4.0) redirected output `feature'?

FX Coudert
In reply to this post by Juan Gallego
> many many thanks. adding the fflush calls to the c_routines does indeed fix
> the problem. i'll try the patch and rebuild gfortran see if that's enough.

Yes, calling fflush should fix the problem. Statically linking
libgfortran could fix it.

But, of course, all those are workarounds. gfortran 4.0.1 and gfortran
CVS does fix this problem for good.

I don't know what system you do have, but regular binaries are available
from gfortran.org on most platforms.

FX