Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28599 Discussions

Bad padding with NUL, character array constructor in initialization of derived type

Harald1
New Contributor II
551 Views

The following code shows an issue with character array constructor in initialization of a derived type:

program p
  implicit none
  type t
     character(3), allocatable :: c(:)
  end type t
  type(t) :: z1, z2
  z1% c =    [ character(1) :: 'b', '*']
  z2    = t( [ character(1) :: 'b', '*'] ) ! bad padding with NUL chars
  print *, ">", z1%c, "<"
  print *, ">", z2%c, "<"
end

 With ifort/ifx I get:

 % ifort ifort-char-array-ctor.f90 -check all,nouninit && ./a.out | cat -ev
 >b  *  <$
 >b*^@^@^@^@<$

Expected: lines 2 and 3 should be identical.

Apparently the constructor in line 8 that initializes z2 lacks a proper typespec to convert from character(1) to character(3).

Works as expected with NAG, gfortran, and some other compiler.

 

0 Kudos
2 Replies
Ron_Green
Moderator
502 Views

The plot thickens.

I tested with an early build of the upcoming 2024.0.  It's better, but still not correct.  

ifx -V -what ifort-char-array-ctor.f90 
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2024.0.0 Build xxxxxxxx
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

Intel(R) Fortran 24.0-1238.2
GNU ld version 2.39-9.fc38
rwgreen@orcsle153:~/quad$ ./a.out
 >b  *  <
 >b*<
rwgreen@orcsle153:~/quad$ gfortran ifort-char-array-ctor.f90 
rwgreen@orcsle153:~/quad$ ./a.out
 >b  *  <
 >b  *  <

We'll open a bug report for this.

0 Kudos
Igor_V_Intel
Employee
459 Views

This bug is escalated to the development team to be fixed.


0 Kudos
Reply