- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
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)
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
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'
Enlace copiado
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
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.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
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'
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
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.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
@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.

- Suscribirse a un feed RSS
- Marcar tema como nuevo
- Marcar tema como leído
- Flotar este Tema para el usuario actual
- Favorito
- Suscribir
- Página de impresión sencilla