- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I've noticed that allocatable character substrings passed to a procedure as arguments are not handled properly (see code below); at least in my computer, instead of upper-case, I get random garbage for the "text" variable. Is it a bug in the compiler or a "requirement" of the Fortran standard (i.e., is the code illegal?)?
program test_allocatable_character
implicit none
integer :: i
character(:), allocatable :: text
character(16) :: text2
integer, parameter :: IBLANK = IACHAR(' ')
text = 'nevermore'
text2 = text
write (*, '(8X, A, A)') 'allocatable ', 'buffer'
do i = 1, MIN(LEN_TRIM(text), LEN_TRIM(text2))
write (*, '("char(", I0, "): ", 5X, A, 9X, A)') i, upper_case(text(i:i)), upper_case(text2(i:i))
enddo
contains
elemental function upper_case(c) result(UC)
character :: UC
character, intent(IN) :: c
integer :: i
continue
i = IACHAR(c)
select case (i)
case (97:122); UC = ACHAR(i - IBLANK)
case default
UC = c
end select
end function
end program test_allocatable_character
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I've noticed that allocatable character substrings passed to a procedure as arguments are not handled properly (see code below); at least in my computer, instead of upper-case, I get random garbage for the "text" variable. Is it a bug in the compiler or a "requirement" of the Fortran standard (i.e., is the code illegal?)?
program test_allocatable_character
implicit none
integer :: i
character(:), allocatable :: text
character(16) :: text2
integer, parameter :: IBLANK = IACHAR(' ')
text = 'nevermore'
text2 = text
write (*, '(8X, A, A)') 'allocatable ', 'buffer'
do i = 1, MIN(LEN_TRIM(text), LEN_TRIM(text2))
write (*, '("char(", I0, "): ", 5X, A, 9X, A)') i, upper_case(text(i:i)), upper_case(text2(i:i))
enddo
contains
elemental function upper_case(c) result(UC)
character :: UC
character, intent(IN) :: c
integer :: i
continue
i = IACHAR(c)
select case (i)
case (97:122); UC = ACHAR(i - IBLANK)
case default
UC = c
end select
end function
end program test_allocatable_character
CTER_ip_UPPER_CASE" doesn't conform to formal argument. See (file:john.f90 line:
14)
john.f90(11): error #12040: actual argument 3 in call of "TEST_ALLOCATABLE_CHARA
CTER_ip_UPPER_CASE" doesn't conform to formal argument. See (file:john.f90 line:
14)
john.f90(11): error #12145: function "TEST_ALLOCATABLE_CHARACTER_ip_UPPER_CASE"
is called as subroutine
$ gfortran -O john.f90
john.f90:4.10:
character(:), allocatable :: text
1
Error: Syntax error in CHARACTER declaration at (1)
john.f90:11.66:
write (*, '("char(", I0, "): ", 5X, A, 9X, A)') i, upper_case(text(i:i)), upper
1
Error: Syntax error in argument list at (1)
john.f90:7.4:
text = 'nevermore'
1
Error: Symbol 'text' at (1) has no IMPLICIT type
The example seems to combine several difficult syntax features, which not all compilers implement, let along diagnose problems correctly.
Even in MR&C, the example of allocatable scalar doesn't rely on automatic allocation.
I can't find a discussion of it in Adams, Brainerd, and the link to Fortran standard on the forum header page isn't working today.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Even in MR&C, the example of allocatable scalar doesn't rely on automatic allocation.
I can't find a discussion of it in Adams, Brainerd, and the link to Fortran standard on the forum header page isn't working today.
Hi tim18,
In Intel Fortran 11.1(.046?), the allocatable character feature is already implemented, although it's still buggy ---that's why I asked if the improper handling of substrings as arguments is a bug in the current implementation or if allocatable character substrings are not allowed to be passed, according the Fortran 2003 standard.
Allocatable characters are not yet implemented in gfortran, according to this page: http://gcc.gnu.org/wiki/Fortran2003Status.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page