I guess that one use case for “type punning” via pointers may be using part of a large chunk of memory allocated at the start of a program in a very legacy-style code (which I struggled with many years ago…) The latter code used a common
block as a memory pool (whose actual memory is allocated via C), passes array elements like X(i1)
and X(i2)
to other subroutines, and then use those memory as work arrays. But if array pointers + c_f_pointer()
are okay to use, the intent of the code may become much clearer (though using allocate
should be much more readable, of course…)
1 Like