public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/34080]  New: Transfer was working, now broken
@ 2007-11-13  9:06 drewmccormack at mac dot com
  2007-11-13 13:56 ` [Bug fortran/34080] [regression] " fxcoudert at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: drewmccormack at mac dot com @ 2007-11-13  9:06 UTC (permalink / raw)
  To: gcc-bugs

I have code that was previously working with gfortran and now is broken. The
problem has to do with the 'transfer' intrinsic. If I transfer a character
string into an array of a different type, and then transfer the array back to a
string, the result is not the original string, but apparently random bytes.

I have prepared sample code to demonstrate:


module TransferBug

   type ByteType
      private
      character(len=1)                                  :: singleByte
   end type

   type (ByteType), save                                :: BytesPrototype(1)

contains

   function StringToBytes(v) result (bytes)
      character(len=*), intent(in)                      :: v
      type (ByteType)                                   ::
bytes(size(transfer(v, BytesPrototype)))
      bytes = transfer(v, BytesPrototype)
   end function

   subroutine BytesToString(bytes, string)
      type (ByteType), intent(in)                       :: bytes(:)
      character(len=*), intent(out)                     :: string
      character(len=1)                                  :: singleChar(1)
      integer                                           :: numChars
      numChars = size(transfer(bytes,singleChar))
      string = ''
      string = transfer(bytes, string)
      string(numChars+1:) = ''
   end subroutine

end module


program main
   use TransferBug
   character(len=100) :: str
   call BytesToString( StringToBytes('Hi'), str )
   print *, trim(str)   ! This should print 'Hi'
end program


-- 
           Summary: Transfer was working, now broken
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: drewmccormack at mac dot com
 GCC build triplet: 4.3.0 20071026 (experimental)
GCC target triplet: powerpc-apple-darwin9.0.0


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


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2007-11-19  5:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-13  9:06 [Bug fortran/34080] New: Transfer was working, now broken drewmccormack at mac dot com
2007-11-13 13:56 ` [Bug fortran/34080] [regression] " fxcoudert at gcc dot gnu dot org
2007-11-13 15:09 ` dominiq at lps dot ens dot fr
2007-11-13 15:51 ` [Bug fortran/34080] [4.3 regression] " burnus at gcc dot gnu dot org
2007-11-13 20:07 ` pault at gcc dot gnu dot org
2007-11-13 20:19 ` pault at gcc dot gnu dot org
2007-11-13 20:28 ` drewmccormack at mac dot com
2007-11-13 20:33 ` pault at gcc dot gnu dot org
2007-11-14  6:12 ` pault at gcc dot gnu dot org
2007-11-19  5:21 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).