# Can writing INTENT(...) declarations be a waste of time?

**URL:** <https://fortran-lang.discourse.group/t/can-writing-intent-declarations-be-a-waste-of-time/10839>\
**Category:** Uncategorized\
**Created:** [April 9, 2026, 12:23pm UTC](https://fortran-lang.discourse.group/t/can-writing-intent-declarations-be-a-waste-of-time/10839 "2026-04-09T12:23:10Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [April 10, 2026, 2:46am UTC](https://fortran-lang.discourse.group/t/can-writing-intent-declarations-be-a-waste-of-time/10839/21 "2026-04-10T02:46:59Z")

</div>

It’s a promise made by the programmer, so the MAYBE part hits home.  
In hindsight designating arguments mutable and the default being immutable like in Rust would have been nice. It is actually enforced by the compiler and the syntax (& and &mut) is relatively compact and easy to discern visually.

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [April 10, 2026, 2:51am UTC](https://fortran-lang.discourse.group/t/can-writing-intent-declarations-be-a-waste-of-time/10839/22 "2026-04-10T02:51:03Z")

</div>

I like that. INTENT(). Works for me. I might even change my comments to !INTENT() to mark where I intentionally do not want an INTENT specified.

---

<div class="post-metadata">

**Author:** ![JohnCampbell](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@JohnCampbell](https://fortran-lang.discourse.group/u/JohnCampbell)\
**Post date:** [April 10, 2026, 7:15am UTC](https://fortran-lang.discourse.group/t/can-writing-intent-declarations-be-a-waste-of-time/10839/23 "2026-04-10T07:15:51Z")

</div>

> [@Beliavsky](#):
>
> For example, `intent(out)` deallocates allocatable arguments.

I presume this is on entry to the routine.  
This is what worries me about using INTENT.  
There is uncertainty of what happens if the variable was not updated, but again with intent(out), it should have been updated.

---

<div class="post-metadata">

**Author:** ![ricriv](https://avatars.discourse-cdn.com/v4/letter/r/f17d59/32.png) [@ricriv](https://fortran-lang.discourse.group/u/ricriv)\
**Post date:** [April 10, 2026, 7:20am UTC](https://fortran-lang.discourse.group/t/can-writing-intent-declarations-be-a-waste-of-time/10839/24 "2026-04-10T07:20:57Z")

</div>

Thanks, now I learned that `intent` is a compile time check, and becomes a run time one only when this isn’t possible.

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [April 10, 2026, 8:47am UTC](https://fortran-lang.discourse.group/t/can-writing-intent-declarations-be-a-waste-of-time/10839/25 "2026-04-10T08:47:58Z")

</div>

@ricriv Not quite. A conformant compiler is _required_ to perfom _some_ compile-time checks for some `intent` (e.g. checking that an intent(in) dummy is not redefined at any point), but not all of them (checking that an `intent(out)` dummy is fully defined in all cases would be a too complex task, and even impossible in many cases at compile time).

Then, compilers are allowed to perform all possible run-time checks, but none of them is required. For performance reasons, runtime checks are usually disabled by default and/or enabled only in debug mode.

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [April 10, 2026, 9:45am UTC](https://fortran-lang.discourse.group/t/can-writing-intent-declarations-be-a-waste-of-time/10839/26 "2026-04-10T09:45:34Z")

</div>

I was inspired by this thread to write a small program to check the way compilers handle these intent() clauses. The attached program shows that at least flang, gfortran and ifx can detect the violations if you help them to via explicit intent(). If there is no intent in the routine setvia, then they all three accept the program source and produce an executable. If there is, the program is rejected.  
[chk\_intentin\_set\_via.f90](https://fortran-lang.discourse.group/uploads/short-url/vpTx4E5RXW9kGbkEpo7c8PD7IqT.f90) (1.0 KB)

---

<div class="post-metadata">

**Author:** ![themos](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/themos/32/521_2.png) [@themos](https://fortran-lang.discourse.group/u/themos)\
**Post date:** [April 10, 2026, 10:17am UTC](https://fortran-lang.discourse.group/t/can-writing-intent-declarations-be-a-waste-of-time/10839/27 "2026-04-10T10:17:45Z")

</div>

> [@jwmwalrus](#):
>
> does the compiler actually have to generate more code under certain circumstances?

No, it does not. Unspecified `INTENT` is a YOLO thing, you promise the compiler that you will never make a mistake, and a decent compiler will take you at your word. On the other hand, you also are not giving it any hints that it can use to optimize execution. Marking a dummy as `INTENT(IN)` can help optimize across statements in the same way that we discussed in [Quiz : So, you think you know Fortran expressions](https://fortran-lang.discourse.group/t/quiz-so-you-think-you-know-fortran-expressions/10735) about a single statement.

> [@jwmwalrus](#):
>
> What about `INTENT(MAYBE_COPY_ON_WRITE)`?

If syntax is required for “unspecified INTENT”, I think `INTENT(UNSPECIFIED)` seems the obvious choice. It could be coupled with an `IMPLICIT NONE(INTENT)` which will reject code that doesn’t explicitly specify `INTENT` for all dummies.

---

<div class="post-metadata">

**Author:** ![wspector](https://avatars.discourse-cdn.com/v4/letter/w/47e85d/32.png) [@wspector](https://fortran-lang.discourse.group/u/wspector)\
**Post date:** [April 10, 2026, 4:30pm UTC](https://fortran-lang.discourse.group/t/can-writing-intent-declarations-be-a-waste-of-time/10839/28 "2026-04-10T16:30:31Z")

</div>

> [@ricriv](#):
>
> Thanks, now I learned that `intent` is a compile time check, and becomes a run time one only when this isn’t possible.

As mentioned upthread, there are several cases where intent is more than a compile-time check, and certainly can change how a compiler compiles code. The derived type with initializers/intent(out) is one case. Details of allocatable arguments are another.

---

<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:** [April 10, 2026, 6:40pm UTC](https://fortran-lang.discourse.group/t/can-writing-intent-declarations-be-a-waste-of-time/10839/29 "2026-04-10T18:40:11Z")

</div>

> [@wspector](#):
>
> The derived type with initializers/intent(out) is one case. Details of allocatable arguments are another.

Yes, an `intent(out)` argument that is a derived type with default initialization is reset to those values upon entry. There is also the situation with a derived type with a finalizer, where the final subprogram is invoked automatically upon entry. A feature of both of these cases is that the compiler must always perform this operation upon entry, so if the programmer does it explicitly before the subprogram call, it is just wasted effort. In the allocatable case, the compiler can at least check the allocation status and do conditional deallocation, but in these other cases it is not so straightforward for a compiler to test for modification status. Thus in a limited sense, these conventions lead to more obscure code rather than clearer code, which I think is the basis for the original post in this thread.

These triggers can also be combined. One example I’ve used before is an allocatable linked list dummy argument with a recursive allocatable component. With `intent(out)` the whole linked list is recursively deallocated upon entry. The problem is that this first-to-last recursive deallocation is not necessarily the best way to deallocate the list, so although is is handy and convenient, it is not necessarily the most efficient (which is from last to first).

I remember another odd situation with an `optional, allocatable, intent(out)` dummy argument. I think this was with the intel fortran compiler about 10 years ago. For some reason, it did not do the required deallocation on entry, so when the subsequent allocatable statements were executed it generated run time errors. I had to hack the code for a few years to do a manual deallocation on entry. The hack had to outlive the compiler bug fix because I wanted the code to work with both current and past versions of that compiler.

I guess the issue is that these features are used by programmers, and they cannot really be avoided unless `intent(out)` is avoided, and that by itself would lead to compromises on code clarity and efficiency.

Are there any other ways that `intent(out)` is used by programmers to simplify codes, and are there any associated gotchas?

[Previous page](https://fortran-lang.discourse.group/t/can-writing-intent-declarations-be-a-waste-of-time/10839.md?page=1)
