Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8684335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:16:51+00:00 2026-06-12T22:16:51+00:00

the code program asd real,pointer :: a,b,c allocate(a) a=2.0 b=>a c=>a deallocate(b) ! print

  • 0

the code

program asd

real,pointer        :: a,b,c

allocate(a)
a=2.0
b=>a
c=>a
deallocate(b) !
print *, associated(c,target=a) ! T

end program

return T with intel compiler. I conclude that “b” is not a full alias of “a”, since I can not deallocate “a” taking “b”.
So my question is: if I construct a pointer with

function ptr
  real,pointer   :: var,ptr
  allocate(var)
  ptr=>var
end function

It is possible to deallocate var after to call this function?

Thank a lot-

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:16:53+00:00Added an answer on June 12, 2026 at 10:16 pm

    The standard says (section 6.3.3.2):

    … Deallocating a pointer target causes the pointer association status of
    any other pointer that is associated with the target or a portion of the target to become undefined.

    Further on, in section 16.4.2.1, it says:

    A pointer may have a pointer association status of associated, disassociated, or undefined.

    and in note 16.3 it points out that:

    A pointer from a module program unit may be accessible in a subprogram via use association.
    Such pointers have a lifetime that is greater than targets that are declared in the subprogram,
    unless such targets are saved. Therefore, if such a pointer is associated with a local target, there is
    the possibility that when a procedure defined by the subprogram completes execution, the target
    will cease to exist, leaving the pointer “dangling”. This standard considers such pointers to have
    an undefined association status. They are neither associated nor disassociated. They shall not be
    used again in the program until their status has been reestablished. There is no requirement on a
    processor to be able to detect when a pointer target ceases to exist.

    All of that is to say that the result of .TRUE. from Intel you are getting is compiler-specific because c has an undefined association status, which compilers can report any way they want. If you tried to access a through c, you would get a memory error (or even if it works, it is undefined and not a guarantee).

    Likewise, your example function is just as dangerous because there is no guarantee that var will exist when the function returns, meaning the ptr function result is again undefined. So again, if you tried to access var through the result of ptr, you would again get a memory error.

    If you want your function to work, it would need to look like:

    function ptr
      real, pointer, save :: var
      real,pointer   :: ptr
      allocate(var)
      ptr=>var
    end function
    

    Of course, this begs the ultimate question — why ALLOCATE pointers? It’s much safer to use ALLOCATABLE for the target and give it the TARGET attribute.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is my code: Program Fortran_Project1 IMPLICIT NONE INTEGER:: i REAL*4:: NORM INTEGER,PARAMETER:: N=5
I am getting an unexpected Access Violation error in the following code: program Project65;
I have below code: class Program { static void Main(string[] args) { Task[] tasks
Here's some code (full program follows later in the question): template <typename T> T
Is there any program code that can help me to pop up the virtual
I have the following code: class Program { static void Main(string[] args) { new
First look at this code: class Program { static void Main(string[] args) { var
I need to write a C++ code coverage program that takes in another C++
i have written the following code class Program { static void Main(string[] args) {
Assume that we have the following code: class Program { static volatile bool flag1;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.