https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110360

--- Comment #31 from David Edelsohn <dje at gcc dot gnu.org> ---
Yes, &"B"[1], is not shifted because it is a reference.  The important
different is "B" is passed left-shifted, but 65 is passed right-shifted.

  call val  ("B","B")          OK
  call val  ("A",char(65))     OK
  call val  ("A",char(a))      WRONG
  call val  ("A",mychar(65))   WRONG
  call val  ("A",mychar(a))    WRONG
  call val  ("1",c)
  call val  ("1",(c))

  subroutine val (x, c)
    character(kind=1), intent(in) :: x  ! control: pass by reference
    character(kind=1), value      :: c
    print *, "by value(kind=1): ", x
    print *, "by value(kind=1): ", c
  end

  character function mychar (i)
    integer, intent(in) :: i
    mychar = char (i)
  end

I'm confused that char(65) produces correct code, while char(a), mychar(65) and
mychar(a) all produce incorrect code, especially char(65) versus char(a), where
a=65.  If I check in mychar, it receives the value 65 and char(65) produces
'A'. I don't understand why GFORTRAN believes that char(65) should produce a
left-shifted value, and "A" passed by reference is shifted in memory to compare
correctly.

Reply via email to