public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/29951]  New: incorrect conversion from string to integer by convert()
@ 2006-11-23  9:24 kloedej at knmi dot nl
  2006-11-23  9:28 ` [Bug fortran/29951] " kloedej at knmi dot nl
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: kloedej at knmi dot nl @ 2006-11-23  9:24 UTC (permalink / raw)
  To: gcc-bugs

Dear people,

The sample code below converts 4 characters to an integer using the transfer
function. If the characters are stored in an array of characters this works
fine. If the characters are stored in a string the transfer fails.

The following commands were used to compile with both gfortran and pgf90 (also
ifort and g95 give the same output as pgf90):
gfortran -o test_convert test_convert.F90
pgf90 -o test_convert test_convert.F90

When executed the program produces the following output:

pgf90 result:
 byte_string =           157          127          100            0
 byte_array  =           157          127          100            0
 byte_string: value =       6586269
 byte_array:  value =       6586269
 byte_string holds             4  bytes
 byte_array holds             4  bytes

gfortran result:
 byte_string =          157         127         100           0
 byte_array  =          157         127         100           0
 byte_string: value =          157
 byte_array:  value =      6586269
 byte_string holds            4  bytes
 byte_array holds            4  bytes

sample code:

program test_convert

  implicit none
  character(len=4)              :: byte_string
  character(len=1),dimension(4) :: byte_array
  integer*4 :: value,n,i

  byte_string(1:1) = char(157)
  byte_string(2:2) = char(127)
  byte_string(3:3) = char(100)
  byte_string(4:4) = char(0)

  byte_array(1:4) = (/char(157),char(127),char(100),char(0)/)

  print *,"byte_string = ",(ichar(byte_string(i:i)),i=1,4)
  print *,"byte_array  = ",(ichar(byte_array( i:i)),i=1,4)

  value = transfer(byte_string(1:4),value)
  print *,"byte_string: value = ",value
  value = transfer(byte_array(1:4),value)
  print *,"byte_array:  value = ",value

  inquire(iolength=n) byte_string
  print *,"byte_string holds ",n," bytes"
  inquire(iolength=n) byte_array
  print *,"byte_array holds ",n," bytes"

end program test_convert

If I understand correctly transfer() should only look at the second parameter
(and the optional size parameter) to decide whether the result should be a
scalar or an array.
At least this is what Metcalf and Reid say in their book fortran90/95
explained. 

However, gfortran seems to look at the rank of the first parameter as well.

best regards,

Jos de Kloe


-- 
           Summary: incorrect conversion from string to integer by convert()
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kloedej at knmi dot nl


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


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

end of thread, other threads:[~2007-01-23  5:15 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-23  9:24 [Bug fortran/29951] New: incorrect conversion from string to integer by convert() kloedej at knmi dot nl
2006-11-23  9:28 ` [Bug fortran/29951] " kloedej at knmi dot nl
2006-11-23 11:17 ` [Bug fortran/29951] incorrect conversion from string to integer by TRANSFER() burnus at gcc dot gnu dot org
2006-11-23 11:40 ` burnus at gcc dot gnu dot org
2006-11-24  3:00 ` pinskia at gcc dot gnu dot org
2006-11-24  8:12 ` kloedej at knmi dot nl
2006-11-24  8:14 ` [Bug fortran/29951] [4.3 Regression] " pinskia at gcc dot gnu dot org
2006-11-24 22:46 ` pinskia at gcc dot gnu dot org
2006-11-25 21:44 ` pinskia at gcc dot gnu dot org
2006-11-25 21:45 ` pinskia at gcc dot gnu dot org
2006-11-27  8:22 ` kloedej at knmi dot nl
2007-01-23  5:15 ` 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).