- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello!
I run into the following problem with LEN() function returning a wrong value for an allocated CHARACTER string after an assignment. Short Example:
CHARACTER(:), ALLOCATABLE :: cStr
INTEGER :: N = 32, iLen
ALLOCATE(CHARACTER(N) :: cStr)
iLen = LEN(cStr) ! = 32 (OK)
! 123456789x123456
cStr = '13 characters'
iLen = LEN(cStr) ! = 13 (NOT OK)
I have tested this under Win7 IFORT 15.0.4.221 and Win10 with IFORT 19.0.8.324, on both platforms IA-32 and x64 .
To me, this appears to be a bug. Am I wrong?
Joerg Kuthe
(working for Intel Elite Resellers qtsoftware.de and polyhedron.com)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That option does not apply to allocatable deferred-length character, which was new in F2008. The standard-conforming behavior is the only one available.
You can avoid the reallocation with:
cStr(:) = '13 characters'
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
allocate LHS (left hand side) came in at Fortran 2003(?) so your assignment reallocates the string to 13 chars. If you want the old standard behaviour there is a compiler option for that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That option does not apply to allocatable deferred-length character, which was new in F2008. The standard-conforming behavior is the only one available.
You can avoid the reallocation with:
cStr(:) = '13 characters'
- 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
Re: your comment upthread, "That option does not apply to allocatable deferred-length character, which was new in F2008" - I do not think that is accurate.
Fortran 2003 introduced support for both deferred length objects (including scalar) of CHARACTER intrinsic type and the intrinsic assignment semantics of allocation (or reallocation) of variable to conform to 'expr' including that for deferred length scalar objects of CHARACTER intrinsic type.
Readers can look up Note 7.35 in section 7.4.1.3 Interpretation of intrinsic assignments in the 2003 standard document.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@FortranFan , yes, you are correct. This is indeed a F2003 feature. Nonetheless, I am also correct that the ifort option /assume:realloc_lhs does not apply to deferred-length character. It did in an early beta at one time, but I successfully argued at the time that this was a new feature and didn't warrant a "do it the old way" compatibility option.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page