Associated

Function Type

The associated function works on all pointer and target variables regardless of their type status.

Function Purpose

This function checks the association status of a pointer. If the function is given only a pointer as an argument, it will return a value of true if the pointer is associated and a value of false if it is not. If both a pointer and a target are passed to the function, then the function will return a value of true if the pointer is associated with the target and a value of false is returned if the pointer is not associated with the target.

Arguments

associated (Pointer,Target)

Pointer (required)

This argument obviously must be a variable that has been declared with the pointer attribute. It is worthy to note that a pointer of any type can be used as an argument though.

Target (optional)

This argument can be of either type target or pointer. This is an optional argument and is used only if you want to check to see if the pointer argument is associated with a particular target or if it is associated with the same target as the target argument ( this is the case if a pointer is passed as the target argument ).

Results and Examples

Before we explore the different results of this function, it will be helpful if we first declare a few variables and make a few assignments.

		real, target :: t1, t2
		real, pointer :: p1, p2, p3, p4
		logical l1, l2, l3, l4
		nullify (p1,p2,p3,p4)
		P1 => t1
		p2 => t1
		p3 => t2
		l1 = associated (p3)
		l2 = associated (p1,t2)
		l3 = associated (p2,p1)
		l4 = associated (p4)

Alright, now that we have something to work with, we can begin to explore how the associated function works. The first call to the associated function will result in a value of true being stored in l1 because the pointer p3 is associated with a target. On the other had, l2 will have the value false stored in it because even though p1 is associated, it is not associated with the target t2. Next, the value of l3 will be true since both pointers p2 and p1 are associated with the same target.

Finally, we come to the last call to the associated function. As you might have guessed, the value of l4 will be false since p4 is not associated, but there is something important that needs to be discussed here. If I had not changed p4 status from undefined to disassociated with the nullify statement, a compiler error or an execution error may have occurred as a result of this call to the associated function. According to the FORTRAN 90 standard, a pointer can not have a value of undefined when it is used as an argument to the associated function. On the Hammond Workstations, this does not appear to be a problem. They seem to handle an undefined pointer by just returning a value of false for its association status. This may not be the case on other machines so be careful!!

For more information and examples see

lecture forty two

examples: associated.f

Up one level / Home


Written by Jason Wehr : jcw142@psu.edu and Maintained by John Mahaffy : jhm@cac.psu.edu

Up one level / Home


Written by Jason Wehr : jcw142@psu.edu and Maintained by John Mahaffy : jhm@cac.psu.edu