- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The following command ALLOCATE(MY_ARRAY(-10),STAT=ERROR) will not return an error (ERROR=0 and MY_ARRAY is allocated to size 0).
This is bit bizarre!? Why was the ALLOCATE commandimplemented in such a way? It *would* seem more logical to trigger an error for this type of scenario.
Just out of curiosity...
Olivier
This is bit bizarre!? Why was the ALLOCATE commandimplemented in such a way? It *would* seem more logical to trigger an error for this type of scenario.
Just out of curiosity...
Olivier
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - opmkl
The following command ALLOCATE(MY_ARRAY(-10),STAT=ERROR) will not return an error (ERROR=0 and MY_ARRAY is allocated to size 0).
This is bit bizarre!? Why was the ALLOCATE commandimplemented in such a way? It *would* seem more logical to trigger an error for this type of scenario.
Just out of curiosity...
Olivier
This is bit bizarre!? Why was the ALLOCATE commandimplemented in such a way? It *would* seem more logical to trigger an error for this type of scenario.
Just out of curiosity...
Olivier
Bizarre? Maybe ...
However, this behavior is exactly specified in the standard.
This is from Section 6.3.1 ALLOCATE statement. I bolded the section of the paragraph that applies to your example.
When an ALLOCATE statement is executed for an array, the values of the lower bound and upper bound expressions determine the bounds of the array. Subsequent redefinition or undefinition of any entities in the bound expressions do not affect the array bounds. If the lower bound is omitted, the default value is 1. If the upper bound is less than the lower bound, the extent in that dimension is zero and the array has zero size.
I hope this helps --
- Lorri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Lorri for pointing out at this section of the standard. I just had to track down a bug in my code because of this. The variable that specifies the size of my allocatable array had become negative prior to the allocation itself- and I didn't think Fortran would not be able to catch this. So now I just need to add one more test for my allocations.
Thanks!
Olivier
Thanks!
Olivier
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - opmkl
Thanks Lorri for pointing out at this section of the standard. I just had to track down a bug in my code because of this. The variable that specifies the size of my allocatable array had become negative prior to the allocation itself- and I didn't think Fortran would not be able to catch this. So now I just need to add one more test for my allocations.
Thanks!
Olivier
Thanks!
Olivier
Oliver,
I am wondering if you have Check array and string bounds on. (Project>YourProject properties>Fortran>Runtime>Check Array and string bounds).
If not, turn it on (Yes(/check:bounds)) and see what it does.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page