Character array constructor with len=* bug?

Character array constructor with len=* bug?

I am running version: ifort (IFORT) 12.1.5 20120612

My problem is basically that when characters are passed to a subroutine with len=*, the array constructor does not automatically take the maximum length as specified, but instead uses the length of the last argument to specify the type. This leads to truncated strings in some cases. If the lengths of a and b in the code snippet below are explicitly specified in the declaration, the constructor works correctly. If the constructor is explicitly typed, the constructor also works correctly.

Example Code:

module tst_char
 contains
    subroutine write_char(a, b)
    character(len=8), dimension(2) :: chars
    character(len=*), intent(in) :: a
    character(len=*), intent(in) :: b

    chars = (/ a , b /)
    write(*,*) 'array first element; auto constructor: ', chars
    chars = (/ character(len=20) :: a , b /)
    write(*,*) 'array first element; specified constructor: ', chars
    write(*,*) '-----'
    end subroutine write_char
end module tst_char

program run_char 
    use tst_char
    call write_char('short', 'longer')
    call write_char('longer', 'short')
    call write_char('longer', 's')
end program run_char

Output:

 array first element; auto constructor: short   longer  
 array first element; specified constructor: short   longer  
 -----
 array first element; auto constructor: longe   short   
 array first element; specified constructor: longer  short   
 -----
 array first element; auto constructor: l       s       
 array first element; specified constructor: longer  s       
 -----

The snippet is also attached for convenience.

Patrick

AnexoTamanho
Download arr_con.f90627 bytes
3 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

It does appear to be a defect in the older 12.1 release. I do not have a specific internal tracking id to associate with this but it does appear this has been fixed in the current 14.0 release so you can upgrade at your convenience to obtain the fix.

Here's the output using the latest Composer XE 2013 SP1 Update 3 (14.0 compiler).

$ ifort -V
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 14.0.3.174 Build 20140422
Copyright (C) 1985-2014 Intel Corporation.  All rights reserved.

$ ifort u516993.f90
$ ./a.out
 array first element; auto constructor: short   longer
 array first element; specified constructor: short   longer
 -----
 array first element; auto constructor: longer  short
 array first element; specified constructor: longer  short
 -----
 array first element; auto constructor: longer  s
 array first element; specified constructor: longer  s
 -----

It appears this was first fixed in the earlier Composer XE 2013 (13.0 compiler) initial release (noted below). I do not see the fix in any 12.1 compiler though.

$ ifort -V
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 13.0.0.079 Build 20120731

 

Faça login para deixar um comentário.