Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

passing optional arguments

Roman1
New Contributor I
655 Views

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

 

0 Kudos
4 Replies
mecej4
Honored Contributor III
655 Views

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.

0 Kudos
Steven_L_Intel1
Employee
655 Views

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.

0 Kudos
Roman1
New Contributor I
655 Views

Thanks for the explanation, it makes sense now.  I thought that restriction (5) was only for derived types.
 

0 Kudos
Steven_L_Intel1
Employee
655 Views

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.

0 Kudos
Reply