# A derived type containing a callback function as a member

**URL:** <https://fortran-lang.discourse.group/t/a-derived-type-containing-a-callback-function-as-a-member/2364>\
**Category:** Help\
**Created:** [December 3, 2021, 6:34am UTC](https://fortran-lang.discourse.group/t/a-derived-type-containing-a-callback-function-as-a-member/2364 "2021-12-03T06:34:20Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [December 3, 2021, 12:43pm UTC](https://fortran-lang.discourse.group/t/a-derived-type-containing-a-callback-function-as-a-member/2364/5 "2021-12-03T12:43:14Z")

</div>

> [@plevold](#):
>
> Notice here that `a` is defined in `main`, but accessible inside `func` due to the use of `contains` and because it is _not_ pure.

Thanks for the code example. The program compiles and runs, giving the same result with gfortran and ifort, even if `func` is declared `pure`. A `pure` function can access a variable such as `a` but cannot change it. I believe `func` cannot be declared [simple](https://fortran-lang.discourse.group/t/designating-simple-procedures/1644) (a feature of Fortran 202x) because it accesses `a`.

---

_[View the full topic](https://fortran-lang.discourse.group/t/a-derived-type-containing-a-callback-function-as-a-member/2364)._
