Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between nullify(pointer) and pointer => null()

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?

like image 910
PVitt Avatar asked Oct 31 '14 12:10

PVitt


People also ask

What is difference between void pointer and null pointer?

The null pointer is basically used in a program to assign the value 0 to a pointer variable of any data type. The void pointer, on the other hand, has no value assigned to it and we use it to store the addresses of other variables in the program- irrespective of their data types.

What is the difference between an uninitialized pointer and a null pointer?

A null pointer should not be confused with an uninitialized pointer: a null pointer is guaranteed to compare unequal to any pointer that points to a valid object. However, depending on the language and implementation, an uninitialized pointer may not have any such guarantee.

What is difference between void and null?

A void is nothing but takes up space; null is nothing at all. In other words, you could measure a void but null offers nothing to measure. 4.1 Void is used to indicate that a function/method does not return any data type. Null indicates that a pointer variable is not pointing to any address.

WHAT IS null pointer difference?

A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.


1 Answers

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).

like image 183
Vladimir F Героям слава Avatar answered Sep 29 '22 17:09

Vladimir F Героям слава