This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Locales in C effect read in Fortran
- From: Dirk Spelsberg <dsp at chemie dot uni-kl dot de>
- To: fortran at gcc dot gnu dot org
- Date: Wed, 23 Dec 2015 11:23:54 +0100
- Subject: Locales in C effect read in Fortran
- Authentication-results: sourceware.org; auth=none
It took me quite a while to sort this out. The program attached works
with English locales but not with German ones. Apparently the decimal
point is replaced by a decimal comma somewhere during the read.
program bug
implicit none
interface
subroutine mklocal() bind(c)
end subroutine mklocal
end interface
character(3)::str='1.8'
real*8::r
call mklocal()
str='1.8'; read(str,*) r; write(6,*) 'str,r:"',str,'", ',r
end program
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
void mklocal()
{
if (setlocale(LC_ALL,"de_DE.UTF-8")==NULL) {printf("Cannot set german locales.\n"); exit(-1);}
// if (setlocale(LC_ALL,"en_GB.UTF-8")==NULL) {printf("Cannot set english locales.\n"); exit(-1);}
}