<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Using Optional assumed-shape array  in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908588#M82817</link>
    <description>&lt;P&gt;The compiler is not required to detect all non-standard usages. In this case, the reference is only non-standard if the argument is omitted. You might have done a PRESENT test before passing it.&lt;/P&gt;
&lt;P&gt;You are correct that the second example with Obj%Base is also not allowed.&lt;/P&gt;</description>
    <pubDate>Tue, 26 Jan 2010 19:01:46 GMT</pubDate>
    <dc:creator>Steven_L_Intel1</dc:creator>
    <dc:date>2010-01-26T19:01:46Z</dc:date>
    <item>
      <title>Using Optional assumed-shape array</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908582#M82811</link>
      <description>&lt;P&gt;Is there a special restriction on the "presence" of (an element from) assumed-shape optional array?&lt;BR /&gt;&lt;BR /&gt;The program below throws access-violation at the call to "SomeMethod" when run in the debug mode if array M is assumed-shape. It works fine if array M has dimension specified (i.e. the commented-out line).&lt;/P&gt;
&lt;P&gt;Abhi&lt;/P&gt;
&lt;P&gt;p.s. Intuitively, may I say that it somewhat makes sense that when an element from an absent array is referred to, there can be a problem. But then it would be valid for any such variable and passing on the presence would not work at all. Humn, I am confused....&lt;/P&gt;
&lt;P&gt;----&lt;/P&gt;
&lt;P&gt;Module OptionalArray&lt;BR /&gt; Implicit None&lt;BR /&gt; Private&lt;BR /&gt; Integer :: nL&lt;BR /&gt; Public :: nL&lt;BR /&gt; Public :: ExposedMethod&lt;BR /&gt; Contains&lt;BR /&gt; Subroutine ExposedMethod(Strng, M)&lt;BR /&gt; Character(*), Intent(IN) :: Strng&lt;BR /&gt; Integer, Intent(IN), Optional :: M(:)&lt;BR /&gt; !Integer, Intent(IN), Optional :: M(nL)&lt;BR /&gt; Print *, Trim(Strng)&lt;BR /&gt; Call SomeSub(Strng, M(1))&lt;BR /&gt; End Subroutine ExposedMethod&lt;BR /&gt; &lt;BR /&gt; Subroutine SomeSub(strng, i)&lt;BR /&gt; Implicit None&lt;BR /&gt; Character(*), Intent(IN) :: strng&lt;BR /&gt; Integer, Intent(IN), Optional :: i&lt;BR /&gt; if (Present(i)) then&lt;BR /&gt; Print *, " integer argument is present."&lt;BR /&gt; else&lt;BR /&gt; Print *, " integer argument is absent."&lt;BR /&gt; endif&lt;BR /&gt; End Subroutine SomeSub&lt;BR /&gt;&lt;BR /&gt; End Module OptionalArray&lt;BR /&gt;&lt;BR /&gt; Program Test_Optional&lt;BR /&gt;&lt;BR /&gt; Use OptionalArray&lt;BR /&gt; &lt;BR /&gt; Implicit None&lt;BR /&gt; &lt;BR /&gt; Integer :: Q(10)&lt;BR /&gt; &lt;BR /&gt; Q = 1&lt;BR /&gt; nL = Size(Q)&lt;BR /&gt; &lt;BR /&gt; Print *, "First Call"&lt;BR /&gt; Call ExposedMethod("With Argument", Q)&lt;BR /&gt;&lt;BR /&gt; Print *, "Second Call"&lt;BR /&gt; Call ExposedMethod("Without Argument")&lt;BR /&gt;&lt;BR /&gt; End Program Test_Optional&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2010 01:21:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908582#M82811</guid>
      <dc:creator>abhimodak</dc:creator>
      <dc:date>2010-01-26T01:21:36Z</dc:date>
    </item>
    <item>
      <title>Using Optional assumed-shape array</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908583#M82812</link>
      <description>&lt;P&gt;You need to add a "USE OPTIONALARRAY" statement to program test_optional. Without this, test_optional doesn't know that exposedmethod has optional arguments, so it doesn't pass any of the additional info to allow the subroutine to know that one of them is not provided.&lt;/P&gt;
&lt;P&gt;I must say I would expect the compiler to throw a warning when it finds 2 calls to the same routine with different numbers of arguments. Did you see any such warnings when you compiled?&lt;/P&gt;
&lt;P&gt;Qolin&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2010 07:53:01 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908583#M82812</guid>
      <dc:creator>qolin</dc:creator>
      <dc:date>2010-01-26T07:53:01Z</dc:date>
    </item>
    <item>
      <title>Using Optional assumed-shape array</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908584#M82813</link>
      <description>Sorry I am blind this morning, its allready there. Need some more coffee...</description>
      <pubDate>Tue, 26 Jan 2010 07:56:06 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908584#M82813</guid>
      <dc:creator>qolin</dc:creator>
      <dc:date>2010-01-26T07:56:06Z</dc:date>
    </item>
    <item>
      <title>Using Optional assumed-shape array</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908585#M82814</link>
      <description>&lt;P&gt;OK let's try again.&lt;/P&gt;
&lt;P&gt;Probably need a judgement from the language police, but I think the use of M(1) counts as an "expression", or some other term, that means it doesn't conform to an "optional argument" for the purposees of being passed (or not) to SomeSub, depending on the presence (or not) of M in the call to ExposedMethod.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2010 08:29:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908585#M82814</guid>
      <dc:creator>qolin</dc:creator>
      <dc:date>2010-01-26T08:29:58Z</dc:date>
    </item>
    <item>
      <title>Using Optional assumed-shape array</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908586#M82815</link>
      <description>&lt;P&gt;F2003 12.4.1.6:&lt;/P&gt;
&lt;P style="padding-left: 20pt;"&gt;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 at least one component selector, array section selector, array element selector, or substring selector shall not be supplied as an actual argument on pain of process death by access violation.&lt;/P&gt;
&lt;P&gt;So you can't do it.&lt;/P&gt;
&lt;P&gt;I think the access violation you see is actually caused by array bounds checking code (/check:bounds) trying to get the necessary bounds information out of the (not...) passed array descriptor for the assumed shape case. That's not required with the explicit shape case, because the bounds are, well... explicit.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2010 11:08:27 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908586#M82815</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2010-01-26T11:08:27Z</dc:date>
    </item>
    <item>
      <title>Using Optional assumed-shape array</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908587#M82816</link>
      <description>&lt;P&gt;Many thanks IanH; that's precisely what I was looking for.&lt;/P&gt;
&lt;P&gt;I was referring to page 477 of the Fortran 2003 Handbook by Adams et al.. I didn't find it among the 11 restrictions specified there but after reading your post and reading the definition of "subobject" on page 27 I find that the handbook entry -- "(6) A subobject of it must not be supplied as an actual argument." means the same thing.&lt;/P&gt;
&lt;P&gt;You are also correct that it is the /check:bounds flag that gives access violation. Removing it would make the program go over it. {I, however, I find it to be untrue for DVF 6.6c where the access violation would come up in the release mode as well which does not have array-string-bounds check option ON.}&lt;/P&gt;
&lt;P&gt;Since this (passing an element from a non-present array) is non-standard, the compiler should catch this error, shouldn't it? and that too regardless of what type of array it is...&lt;/P&gt;
&lt;P&gt;One more question on the subobject being not allowed. Does this mean that the following should not work?&lt;/P&gt;
&lt;P&gt;Subroutine ExposedMethod(n, Obj)&lt;BR /&gt; Implicit None&lt;BR /&gt; Integer, Intent(IN) :: n&lt;BR /&gt; Type(newDerived), Intent(IN), Optional :: Obj&lt;BR /&gt; Call Proc(n, Obj%Base)&lt;BR /&gt; End Subroutine ExposedMethod&lt;/P&gt;
&lt;P&gt;Where the newDerived type is of the form&lt;/P&gt;
&lt;P&gt;Type newDerived&lt;/P&gt;
&lt;P&gt;Type(newBase) :: Base&lt;/P&gt;
&lt;P&gt;End Type newDerived&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Abhi&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2010 17:32:27 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908587#M82816</guid>
      <dc:creator>abhimodak</dc:creator>
      <dc:date>2010-01-26T17:32:27Z</dc:date>
    </item>
    <item>
      <title>Using Optional assumed-shape array</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908588#M82817</link>
      <description>&lt;P&gt;The compiler is not required to detect all non-standard usages. In this case, the reference is only non-standard if the argument is omitted. You might have done a PRESENT test before passing it.&lt;/P&gt;
&lt;P&gt;You are correct that the second example with Obj%Base is also not allowed.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2010 19:01:46 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908588#M82817</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2010-01-26T19:01:46Z</dc:date>
    </item>
    <item>
      <title>Using Optional assumed-shape array</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908589#M82818</link>
      <description>&lt;P&gt;Thanks Steve. I think I understand what you mean. In fact, I have always been using the if (present) then and was just going through the language elements to brush-up things and hence this test.&lt;/P&gt;
&lt;P&gt;Abhi&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2010 20:10:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908589#M82818</guid>
      <dc:creator>abhimodak</dc:creator>
      <dc:date>2010-01-26T20:10:15Z</dc:date>
    </item>
    <item>
      <title>Using Optional assumed-shape array</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908590#M82819</link>
      <description>&lt;P&gt;Just to be clear - in some cases you are allowed to "pass through" the "omitted" aspect to another routine which has the argument also declared as optional. But you have to pass the whole variable, not a "subobject".&lt;/P&gt;
&lt;P&gt;For further reading, see &lt;A target="_blank" href="http://software.intel.com/en-us/forums/showpost.php?p=12903"&gt;Doctor Fortran and the Virtues of Omission&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2010 20:54:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908590#M82819</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2010-01-26T20:54:26Z</dc:date>
    </item>
    <item>
      <title>Using Optional assumed-shape array</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908591#M82820</link>
      <description>&lt;P&gt;Yes Steve, I understand that the "absence" can be passed along; always using if(Present()) then may be considered conservative. With not understanding the "subobject" part, I was wondering if I was violating the standard or not and hence this thread.&lt;/P&gt;
&lt;P&gt;By the way, I had read the Virtues of Omission article a long time back and have liked the 4 lines at the begining of it.&lt;/P&gt;
&lt;P&gt;Abhi&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2010 21:13:11 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-Optional-assumed-shape-array/m-p/908591#M82820</guid>
      <dc:creator>abhimodak</dc:creator>
      <dc:date>2010-01-26T21:13:11Z</dc:date>
    </item>
  </channel>
</rss>

