# gFortran error "Unexpected pointer assignment"

**URL:** <https://fortran-lang.discourse.group/t/gfortran-error-unexpected-pointer-assignment/8640>\
**Category:** GNU\
**Created:** [September 22, 2024, 2:09pm UTC](https://fortran-lang.discourse.group/t/gfortran-error-unexpected-pointer-assignment/8640 "2024-09-22T14:09:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gWyche](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gWyche](https://fortran-lang.discourse.group/u/gWyche)\
**Post date:** [September 22, 2024, 2:09pm UTC](https://fortran-lang.discourse.group/t/gfortran-error-unexpected-pointer-assignment/8640/1 "2024-09-22T14:09:58Z")

</div>

Unexpected pointer assignment statement in …

If you get this and the erring file is a MODULE, then you may forgot to have the assignments below in the CONTAINS section. What you are assigning to **must** be a TARGET.

Further, the assignments must be in a SUBROUTINE or FUNCTION.

If you were converting a set of F77 EQUIVALENCEs to pointer assignments, you could easily overlook MODULE … CONTAINS … process … your\_pointer =\> (not ==\>) fortran\_storage\_with\_TARGET\_attribute

---

<div class="post-metadata">

**Author:** ![RonShepard](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@RonShepard](https://fortran-lang.discourse.group/u/RonShepard)\
**Post date:** [September 22, 2024, 8:44pm UTC](https://fortran-lang.discourse.group/t/gfortran-error-unexpected-pointer-assignment/8640/2 "2024-09-22T20:44:11Z")

</div>

The following code compiles with gfortran 12 (and other versions too, I think). The pointer initialization is “above” the contains, which in this small module doesn’t exist. This is one way to “modernize” f77 equivalences in legacy code. This is roughly the same as the compile time `equivalence (ip,ival)`.

```auto
module xxx
   integer, save, target :: ival
   integer, pointer :: ip => ival
end module xxx

```
