- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I vaguely remember that a while back there was a discussion about the following question - but I forgot what the conclusion was...
Is it standard-conformant to query (with the PRESENT intrinsic) the presence of a dummy argument that has the intent OUT?
I am asking because it is (kind of) similar to the question of whether it is standard-conformant to query (with the ALLOCATED intrinsic) the allocation status of an allocatable dummy argument that has the intent OUT [and the answer here is: no this is not standard conformant].
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Per the standard document, `INTENT` attribute of the received argument does not affect the specific semantics of `PRESENT`. The PRESENT intrinsic shall return true if the received argument corresponds to an actual present argument or to an argument with an allocated ALLOCATABLE attribute or an associated pointer object; false otherwise.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
INTENT(OUT) does have a semantic effect in that the associated effective argument becomes undefined at entry to the procedure. If the argument is allocatable and allocated, it is deallocated. However, this doesn't affect the use of PRESENT. For example:
program main
implicit none
integer, allocatable :: foo
allocate (foo)
call sub (foo)
contains
subroutine sub (bar)
integer, allocatable, intent(out), optional :: bar
print *, "bar is present: ", present(bar)
print *, "bar is allocated: ", allocated(bar)
end subroutine sub
end program main
D:\Projects>ifort t.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.10.0 Build 20230609_000000
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.
Microsoft (R) Incremental Linker Version 14.36.32532.0
Copyright (C) Microsoft Corporation. All rights reserved.
-out:t.exe
-subsystem:console
t.obj
D:\Projects>t.exe
bar is present: T
bar is allocated: F
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ok, thanks for the answers, I stand corrected on both points. I suspect that I picked up the practice of using only INTENT(IN) or INTENT(INOUT) for optional (and for allocatable) arguments a really long time ago when the implementation of those features were still new in the compilers and a bit buggy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'll comment that FortranFan's mention of unallocated allocatables or disassociated pointers being considered not present is a fairly recent addition to the language (F2008 or later). This applies only if the dummy argument is NOT allocatable/pointer.
![](/skins/images/7FC17B7B85029576C25F1E43CE255B51/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page