Error during compilation involving allocate/deallocate

Error during compilation involving allocate/deallocate

Hello!

I'm getting the following series of errors when compiling. Basically there are three types of errors the repeats during the whole code:

This is a sample of the code:

ALLOCATE (P(NP))

PP=> P

And these are the errors that I'm getting.

error #6724: An allocate/deallocate object must have the ALLOCATABLE or POINTER attribute. [P] 
error #8196: An ALLOCATE shape must not be given for a scalar object. [P]
error #6793: The POINTER attribute is required [PP]

I don't know what is the source of the problem neither how to fix it, since the program runs without any problems using the Compaq compiler.

Many thanks

PS. I already tried the the solution: properties>Fortran>Diagnostics>Check Routine Interfaces>NO

10 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

The compiler is complaining about the declaration of P, which you don't show, and so this may be a consequence of another problem which should have been reported earlier.

CVF may have accepted syntax which modern compilers don't.

Ok this is how I declare P

Integer, target, allocatable :: P(:)

The error messages are not consistent with your reported declaration of P. The following example code gets compiled without error, and shows that it is important to report source and error messages without omitting important declarations.


subroutine getptr(PP)

Integer, target, allocatable :: P(:)

integer, pointer, intent(out) :: PP(:)

!

ALLOCATE (P(NP))

PP=> P

!

return

end subroutine getptr

Ok I will try it thanks. I will let you know if it finally works

Please do not use the example code for any purposes other than that intended: to illustrate that it can be compiled with no error messages. Semantically, there are several things wrong with the subroutine code, and using it as-is is an invitation for trouble.

I was about to comment that I don't see the point for the intent statement. Actually I really believe that the syntaxis on my code is ok and I can't understand why I'm getting those errors. The errors are only present when I run the code in the intel compiler.

I'm not allowed to post or send my code, but I can show you another extract if you need to in order to achieve a better insight.

Thank you so much...

Quote:

I was about to comment that I don't see the point for the intent statement.

Specifying the intent is not required, but doing so helps me keep track of the purpose of the variable better. In this case, the pointer is undefined until it is pointer-assigned in the subroutine. As a result, if I had used the pointer variable in an expression before the pointer-assignment, the compiler would have flagged that as an error/warning.

Quote:

Actually I really believe that the syntax on my code is ok and I can't understand why I'm getting those errors.

Since you did not show more than bits of code, and in particular did not show the declarations, we cannot comment. If your beliefs can be traced to sections of the Fortran standard, that would be another matter entirely.

Quote:

The errors are only present when I run the code in the intel compiler.

Recent versions of the Intel compiler do a better job of diagnosing errors than older versions and some other Fortran compilers.

Mecej4,

Could I ask if getptr is an example of memory leakage?
Does the target attribute stop P from being auto DEALLOCATE on exit from getptr.
I would expect that if the memory allocated to P was not released on exit from getptr, then if PP was linked to another memory location or nullified, the memory may not be effectively released.

I am assuming getptr is a valid code in either F2003 or F2008, which I am not familiar with.

John

John,

As I stated in #5, the sample code that I posted was for syntax only, and is next to meaningless. After returning from the subroutine, PP would be a dangling pointer.

If you wish, depending on which language standard you ask the compiler to adhere to, you can use IF (ASSOCIATED(PP)) to track the status of PP.

Leave a Comment

Please sign in to add a comment. Not a member? Join today