STANDARD? Fortran character --> C char with TRANSFER function


[Prev][Next][Index][Thread]

STANDARD? Fortran character --> C char with TRANSFER function



I I would create a "C" char with a Fortran character.
I propose (to me :) use TRANSFER function.
Here a simple program:


----------------------------------------------------------------------------
--------------------------
PROGRAM TEST1


  IMPLICIT NONE


  INTEGER, PARAMETER :: ltxt=15


  CHARACTER   :: TEXT*ltxt
  BYTE        :: Cchar(ltxt+1) ! +1 because C char terminate with 0
  BYTE        :: mold_Cchar(2)
  INTEGER     :: I


  TEXT = 'ABCDEFGHIJKLMNO'
  Cchar = 0
  Cchar = TRANSFER(TEXT,mold_cchar)


   DO I=1,ltxt
    PRINT *,TEXT(I:I), Cchar(i)
  ENDDO
  PRINT *, '= end =',Cchar(i), ' NULL'


END PROGRAM TEST1
----------------------------------------------------------------------------
------------------------------


Question:  safe or not safe use this method of conversion?
                (standard conform?)


         [note: I use DIGITAL Fortran 90, machin AXP]


Thanks


Gilles
ratel@ccfm.ireq.ca