Unbuffered output in mixed C / Fortran programs

Arjen Markus arjen.markus@wldelft.nl
Thu Oct 16 06:23:00 GMT 2008


Brian Dessent wrote:

>Georg Denk wrote:
>
>  
>
>>late. At least this was the result of a small test, where
>>I added a putenv call at the beginning of the main
>>routine (which is in C, but I don't think this makes
>>a difference).
>>    
>>
>
>You might be able to arrange for the putenv to execute before the
>libgfortran initialization routines by:
>
>void whatever() __attribute__((constructor))
>{
>  putenv ("GFORTRAN_UNBUFFERED_PRECONNECTED=y");
>}
>
>If that still doesn't result in it being called early enough you can
>also try giving it the lowest allowable numerical priority, e.g.
>__attribute__((constructor(101))).  I seem to recall that 100 and below
>are reserved for internal use, meaning it might be impossible to supply
>a priority able to cause it to run earlier than internal library init
>routines, but it's worth a try anyway.
>
>Brian
>
>  
>
Another remedy:
As Georg can not directly control the environment in which his program 
is running,
perhaps using a small C program that calls the actual program could do it:

int main( int argc, char *argv[]) {    
     putenv ("GFORTRAN_UNBUFFERED_PRECONNECTED=y");
     system("... actual program ...");
}

Regards,

Arjen





More information about the Fortran mailing list