I do not know whether the following program is valid Fortran 77 (with deleted
parts). The issue is that gfortran creates:

    static character(kind=1) C.1534[1:9] = "HELLO YOU";

which is then passed to an default-kind integer. "HELLO YOU" consists of 9
characters, but a default-kind integer can accommodate for multiples of 4, i.e.
12 characters. Thus, printing with "FORMAT (100A4)" prints more data than
available.

gfortran:
HELLO YOUhfj
:HELLO YOUhfj:
4C4C4548 4F59204F 6A666855
where "od" shows that it prints:
  H   E   L   L   O  sp   Y   O   U   h   f   j  nl

ifort:
HELLO YOU
:HELLO YOU:
4C4C4548 4F59204F       55
   H   E   L   L   O  sp   Y   O   U nul nul nul  nl
i.e. it prints trailing NULs.

NAG f95:
HELLO YOU
:HELLO YOU:
4C4C4548 4F59204F 34280055
   H   E   L   L   O  sp   Y   O   U nul   (   4  nl

sunf95:
HELLO YOU
:HELLO YOU:
4C4C4548 4F59204F       55
  H   E   L   L   O  sp   Y   O   U nul nul nul  nl

open64:
HELLO YOU
:HELLO YOU   :
4C4C4548 4F59204F 20202055
   H   E   L   L   O  sp   Y   O   U  sp  sp  sp  nl

pathscale:
HELLO YOU
:HELLO YOU   :
4C4C4548 4F59204F 20202055
   H   E   L   L   O  sp   Y   O   U  sp  sp  sp  nl

Thus either by zero or by space padding it seems to work in the other
compilers. I wonder what happens with g77.


The program itself:

C     PROGRAM HELLO2
      CALL WRTOUT (9HHELLO YOU, 9)
      STOP
      END
C
      SUBROUTINE WRTOUT (IARRAY, NCHRS)
C
      INTEGER IARRAY(1)
      INTEGER NCHRS
C
      INTEGER ICPW
      DATA ICPW/4/
      INTEGER I, NWRDS
C
      NWRDS = (NCHRS + ICPW - 1) /ICPW
      WRITE (6,100) (IARRAY(I), I=1,NWRDS)
      WRITE (6,101) (IARRAY(I), I=1,NWRDS)
      write(*,'(4(z8," "))') (IARRAY(I), I=1,NWRDS)
      RETURN
  100 FORMAT (100A4)
  101 FORMAT (':',3A4,':')
      END


-- 
           Summary: Output of Hollerith constants which are not a multiple
                    of 4 bytes
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43217

Reply via email to