https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89696
--- Comment #7 from Steve Kargl <sgk at troutmask dot apl.washington.edu> --- On Wed, Mar 13, 2019 at 07:09:19PM +0000, kevin at fai dot host wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89696 > > --- Comment #5 from Khang H. Nguyen <kevin at fai dot host> --- > > program foo > > integer i > > read(*,*) i > > read(*,'(I4)') i > > end program foo > > > > % gfcx -o z a.f90 > > % ./z > > % ./z > > 12 b > > 12 b > > At line 4 of file a.f90 (unit = 5, file = 'stdin') > > Fortran runtime error: Bad value during integer read > > > > The first '12 b' is read a '12'. The second read says the 4 characters > > are an integer, so '12 b' generates an error. > > For that scenario, you absolutely need to know the format of the string and > can't pass the string without knowing the format then? > In the first case, 'read(*,*)', the compiler will do the right thing. In the second case, 'read(*,'(I4)'), the programmer is telling the compiler that when the read occurs there are 4 characters and those four characters are an integer. You could write '12 ' or ' 12' or ' 12 '. The blanks will be stripped. If you write '12 b', 'b' isn't a digit that can be converted to an integer.