- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using Fortran Compiler XE 15.0.1.148 .
When I compile and run the attached program, it crashes with an access violation. The error occurs when an optional array section, that is not present, is passed to another subroutine. There are no errors when I compile the same program with gfortran (4.9.1).
I am not sure if the bug is in the Fortran program, or the compiler. I have checked the standard, and it is not clear if this is allowed.
12.5.2.12 Argument presence and restrictions on arguments not present
3 An optional dummy argument that is not present is subject to the following restrictions.
(1) If it is a data object, it shall not be referenced or be defined. If it is of a type that has default initialization, the initialization has no effect.
... 11 other restrictions.
4 Except as noted in the list above, it may be supplied as an actual argument corresponding to an optional dummy argument, which is then also considered not to be present.
Roman
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You have almost answered your own question. The line in question, line-15, attempts to extract a section of an array variable when that variable is not present. Taking a section amounts to making a reference, I think.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would say that your program, which has:
call sub2( a(2:3) )
violates the following rule of the standard:
12.5.2.12 Argument presence and restrictions on arguments not present
An optional dummy argument that is not present is subject to the following restrictions:
...
(5) A designator with it as the base object and with one or more subobject selectors shall not be supplied as an actual argument.
(2:3) is a subobject selector.
You are allowed only to pass the whole array as an actual argument (to a procedure where the corresponding dummy is OPTIONAL), not a part of the array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the explanation, it makes sense now. I thought that restriction (5) was only for derived types.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, I can see how you might assume that. I had to go read the definition to be sure.
gfortran's behavior is an extension, though I wonder if it's deliberate.

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