-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional conditional reallocation in allocate (reallocatable
attribute)
#318
Comments
Even better, in my opinion, would be a new statement |
reallocatable
attribute)
I'll bring here some of the comments made on the forum.
So, my 2 cents here are: better to integrate reallocation within the already existing allocate. Does an extra argument is required? I think not but would honestly want to see a practical reason for which it would be really needed. |
Here is a proposal, with a demonstration code: https://github.com/PierUgit/enhanced-allocatables I have defined a |
First requested at https://fortran-lang.discourse.group/t/is-allocate-a-function-or-subroutine/2771/6. See also https://fortran-lang.discourse.group/t/reallocatable-attribute/5914 for a more general approach.
It would simplify a lot of my code if
allocate()
had an optional argument to trigger conditional reallocation of an existing array. Say something likeIf
a(:)
is already allocated with lower boundlb
and upper boundub
, then nothing happens, the array is unchanged. Ifa(:)
is already allocated with the correct size but with different bounds, then the bounds are changed but the contents of the array would remain unchanged. Ifa(:)
is already allocated but with a different size, then it is deallocated and reallocated with the new size and bounds. All of this can be done now with some trickery, but these common operations should be a standard part of the language.The text was updated successfully, but these errors were encountered: