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

unexpected behavior of pointer this and allocated arrays

rogcar
Beginner
1,695 Views
Hello there,

I've been trying to use some allocatable arrays in a user-defined data type. After an object is created and the allocatable array is allocated, it may be accessed with no error. But if I point to the object, I'm not able to access the allocated array, usingthe pointer. It seems to loose the array address.

I'm attaching a sample project with the error.

Regards
Roger
0 Kudos
12 Replies
TimP
Honored Contributor III
1,695 Views
I would have expected this to run afoul of scoping, since Fortran requires automatic deallocation when going out of scope. So, you might add diagnostic code to see whether the pointer target remains allocated. Sorry if I have been thrown off track by the coding style.
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,695 Views

If your situation is a scoping error (allocated array goes out of scope) as Tim suggestedbut your coding intention is to keep the object persistant (and accessible via pointer) after exit from subroutine/function that performs allocationthen allocate to the pointer or placethe array (descriptor) in a module (as opposed to onstack).

Jim Dempsey
0 Kudos
Steven_L_Intel1
Employee
1,695 Views
I took a look at this and I think it is a bug. I understand where Tim is coming from, but as "this" is a dummy argument and not a local variable, automatic dealloication does not apply.

What I see is that the pointer is not filled in properly, even in the test program - or at least it looks that way to me. I'll report this to the developers.
0 Kudos
rogcar
Beginner
1,695 Views
Thanks Tim and Jim, but Steve got it right. It's not a problem of going out of scope, because it's not a local variable. Actually, the pointer is correctly addressed at first, but inside a routine, the 'this' pointer looses information. Notice that the pointerin the main routineis still working, correctly addressed.

It is a bug :)

Thanks again,
Roger
0 Kudos
Steven_L_Intel1
Employee
1,695 Views
Issue ID is DPD200140796
0 Kudos
abhimodak
New Contributor I
1,695 Views
Hi

I also notice that the debugger does not display the correct information.

For example,

(1) Just after the allocation in Child2ProcedureSub, debuger shows this%child1%parent%parentvariable as undefined pointer/array.
(2) After returning to the main program, when the type variable itself is put in the watch window, the "parentvariable" is not displayed correctly. Instead of array bounds 1 to 2, it shows as parentvariable(0) with value 0.
(3) child3_var%parentvariable gives "invalid structure".

Regarding point (2) above, I have to put child3_var(1) in the watch-window. If I put jus child3_var, the expanded tree would should only one array element but with element 0. The corresponding value of the parentvariable(0) is displayed as 6369624.

Abhi

p.s. Also I tested the program with XLFortran and it does print 3, 4 as expected.
0 Kudos
Steven_L_Intel1
Employee
1,695 Views
Yes, I noticed that as well and included that in my report. The pointer is displayed incorrectly even before it is allocated.
0 Kudos
rogcar
Beginner
1,695 Views
Yes, I noticed that as well and included that in my report. The pointer is displayed incorrectly even before it is allocated.

Indeed, although it does not display correctly in debug mode, it does work. That's why I'm printing the results in the screen. I believe it was reported before by someone else, at least I remember reading about it. I did notice this behavior, but since it was already reported, and the developers notified, I'm expecting that this bug willl be corrected in the next update.

Actually, why Fortran doesn't have a function like TRACE? It would help a lot.

Regards,
Roger
0 Kudos
Steven_L_Intel1
Employee
1,695 Views
What is TRACE?
0 Kudos
rogcar
Beginner
1,695 Views
What is TRACE?

TRACE is a diagnosis C function that writesout the stack in debug mode. It works only in debug mode, and is a print-like function, but the standard (and only) output is the IDE output window. I notice that there is a similar function in Fortran, but I have not tried it yet: TRACEBACKQQ

Regards,
Roger
0 Kudos
Steven_L_Intel1
Employee
1,695 Views
The problem originally reported has been fixed in our sources. I expect the fix to appear in Update 5, scheduled for late January.
0 Kudos
Steven_L_Intel1
Employee
1,695 Views
I'm not sure why the fix did not appear in Update 5, but it is in 11.1 Update 6, available now.
0 Kudos
Reply