- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This bug is escalated to the development team to be fixed.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page