Skip to content

Commit eaa3c10

Browse files
authored
Update FortranForCProgrammers.md
Refine the text describing differences between C and Fortran pointers to correct an erroneous statement (that pointers cannot point to allocatables). Fixes bug flang-compiler#461.
1 parent 9307806 commit eaa3c10

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

documentation/FortranForCProgrammers.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,23 @@ little like C++17's `std::visit()` on a discriminated union.
260260
Pointers
261261
--------
262262
Pointers are objects in Fortran, not data types.
263-
Pointers can point to data, arrays, and subprograms, but not to other pointers
264-
or to an allocatable.
263+
Pointers can point to data, arrays, and subprograms.
265264
A pointer can only point to data that has the `TARGET` attribute.
266265
Outside of the pointer assignment statement (`P=>X`) and some intrinsic
267266
functions and cases with pointer dummy arguments, pointers are implicitly
268267
dereferenced, and the use of their name is a reference to the data to which
269268
they point instead.
270269

270+
Unlike C, a pointer cannot point to a pointer *per se*, nor can they be
271+
used to implement a level of indirection to the management structure of
272+
an allocatable.
273+
If you assign to a Fortran pointer to make it point at another pointer,
274+
you are making the pointer point to the data (if any) to which the other
275+
pointer points.
276+
Similarly, if you assign to a Fortran pointer to make it point to an allocatable,
277+
you are making the pointer point to the current content of the allocatable,
278+
not to the metadata that manages the allocatable.
279+
271280
Unlike allocatables, pointers do not deallocate their data when they go
272281
out of scope.
273282

0 commit comments

Comments
 (0)