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

Bizarre pointer behaviour with allocatable scalars in user defined types

IanH
Honored Contributor III
989 Views
I have some code which is behaving strangely when I set a pointer to point to an allocatable scalar that is a member of a user defined type.

When I run the attached short stretch of code I get different output from the WRITE statements in the AddElement subroutine, with only the first WRITE giving meaningful output. The confusing extract is

e%content(pos)%element%dbg = 'CL'
p => e%content(pos)%element
WRITE (*,"('1>',A)") e%content(pos)%element%dbg
WRITE (*,"('2>',A)") p%dbg

I would have thought that the two lines of output would have to be the same, even in the face of a gross error somewhere else.

The code works as I would expect if I remove one level of procedure call (set this_is_driving_me_crazy to .FALSE., as far as I can tell B to B is the same code as A to A), or change the allocatable scalar to be a rank one, size one array (lines marked "! C" replace similar lines).

What am I missing????

All this with 11.0.066.

Thanks for any ... pointers ...

IanH
0 Kudos
5 Replies
gib
New Contributor II
989 Views
Quoting - IanH
I have some code which is behaving strangely when I set a pointer to point to an allocatable scalar that is a member of a user defined type.

When I run the attached short stretch of code I get different output from the WRITE statements in the AddElement subroutine, with only the first WRITE giving meaningful output. The confusing extract is

e%content(pos)%element%dbg = 'CL'
p => e%content(pos)%element
WRITE (*,"('1>',A)") e%content(pos)%element%dbg
WRITE (*,"('2>',A)") p%dbg

I would have thought that the two lines of output would have to be the same, even in the face of a gross error somewhere else.

The code works as I would expect if I remove one level of procedure call (set this_is_driving_me_crazy to .FALSE., as far as I can tell B to B is the same code as A to A), or change the allocatable scalar to be a rank one, size one array (lines marked "! C" replace similar lines).

What am I missing????

All this with 11.0.066.

Thanks for any ... pointers ...

IanH
It is interesting that ifort 10.1.011 cannot compile this program. The line
TYPE(Element), ALLOCATABLE :: element
gives
Error: This scalar name is invalid in this context [ELEMENT]
pointing to the member 'element'.
0 Kudos
Steven_L_Intel1
Employee
989 Views
Quoting - gib
It is interesting that ifort 10.1.011 cannot compile this program. The line
TYPE(Element), ALLOCATABLE :: element
gives
Error: This scalar name is invalid in this context [ELEMENT]
pointing to the member 'element'.
Expected - allocatable scalars is a new 11.0 feature.
0 Kudos
Steven_L_Intel1
Employee
989 Views
This is a compiler bug. It is not handling the p%dbg reference properly. I have reported it as issue DPD200111953.
0 Kudos
IanH
Honored Contributor III
989 Views
This is a compiler bug. It is not handling the p%dbg reference properly. I have reported it as issue DPD200111953.

Thanks for the help. I'll work around it in the meantime by using a size one allocatable array.
0 Kudos
Steven_L_Intel1
Employee
989 Views
The developers tell me that this bug has been fixed for the next release (May/June timeframe). Thanks for reporting it.
0 Kudos
Reply