7

What is the difference between

procedure(some_routine), pointer :: ptr
ptr => null()

and

procedure(some_routine), pointer :: ptr
nullify(ptr)

Does nullify do something behind the scenes? Or is it just two different ways of doing the same thing?

PVitt
  • 11,500
  • 5
  • 51
  • 85

1 Answers1

9

The result is completely identical. The assignment sign => can be also used for variable initialization or derived type components default initialization, where the nullify statement is unusable, but that is only a syntactic thing, it is not a proper assignment in fact.

For example

  type t
    real, pointer :: ptr => null()
  end type

is the default initialization of a component, and

 program p
   real, pointer :: ptr2 => null()

is initialization of a variable. The variable ptr2 is implicitly save as any other initialized variable (a common source of errors).