<?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 Re: Allocatable variable question in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-variable-question/m-p/1550637#M169754</link>
    <description>&lt;P&gt;Thanks Andrew &amp;amp; Jim,&lt;/P&gt;&lt;P&gt;I vaguely remember Steve Lionel responded to me many years ago to a similar question regarding the allocation of zero sized arrays but I wasn't sure of the context.&amp;nbsp; Having looked further into my code the zero allocated array was being used after all so that was probably the likely cause of the corruption. The program is huge so trying to create a reproducer will take too long and as everything was working fine until I added this new function I think, fingers crossed, the issue should be resolved now.&lt;/P&gt;&lt;P&gt;Thanks again for taking time to reply&lt;/P&gt;</description>
    <pubDate>Tue, 05 Dec 2023 10:21:41 GMT</pubDate>
    <dc:creator>Stephen_Sutcliffe</dc:creator>
    <dc:date>2023-12-05T10:21:41Z</dc:date>
    <item>
      <title>Allocatable variable question</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-variable-question/m-p/1550474#M169736</link>
      <description>&lt;P&gt;I have been struggling with a bug in my program where, after calling a function which allocated a number of data structure arrays, the program crashed later on with what looks like a stack corruption error when trying to initialise a dialog box a second time:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" size="2"&gt;0xc0000005: access violation reading location 0xFFFFFFFFFFFFFFFF&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;After spending most of the day trying to get to the bottom of this I think I've found the cause.&amp;nbsp;&lt;/P&gt;&lt;P&gt;One of the allocatable arrays was incorrectly allocated with a zero size&amp;nbsp; i.e.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" size="2"&gt;allocate(array(0),stat=ier)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;though it was never used&lt;/FONT&gt;&lt;FONT face="helvetica"&gt;.&lt;/FONT&gt; By resolving this I hope the bug has been fixed as program continues as expected but I wondered:&lt;/P&gt;&lt;P&gt;Is it legal Fortran to assign allocatable arrays with 0 size. If not why aren't such errors trapped by the compiler?&lt;/P&gt;&lt;P&gt;It is ok to allocate an array with the statement such as &lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;allocate(array(0:100),stat=ier)&lt;/STRONG&gt;&lt;/FONT&gt; as this results in an array with size=101.&lt;/P&gt;&lt;P&gt;I'm using latest version of IFORT on Windows.&lt;/P&gt;&lt;P&gt;Has anyone got any thoughts on this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 00:23:24 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-variable-question/m-p/1550474#M169736</guid>
      <dc:creator>Stephen_Sutcliffe</dc:creator>
      <dc:date>2023-12-05T00:23:24Z</dc:date>
    </item>
    <item>
      <title>Re: Allocatable variable question</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-variable-question/m-p/1550483#M169737</link>
      <description>&lt;P&gt;Yes zero size array allocation is legal. I do not see why this would cause a crash if you did not try to use it. Some usage cases would be a problem. If you have stack or other corruption ANY code change can make the code magically work cause you have move things in the memory organisation and you now are corrupting something that is not important.&amp;nbsp; Can you make a reproducer of this problem?&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 00:41:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-variable-question/m-p/1550483#M169737</guid>
      <dc:creator>andrew_4619</dc:creator>
      <dc:date>2023-12-05T00:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: Allocatable variable question</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-variable-question/m-p/1550523#M169740</link>
      <description>&lt;P&gt;&amp;gt;&amp;gt;&lt;SPAN class=""&gt;It is ok to allocate an array with the statement such as&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;&lt;SPAN class=""&gt;allocate(array(0:100),stat=ier)&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;as this results in an array with size=101.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Yes. You can also&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="fortran"&gt;allocate(array(-50:50)
do i = -50, 50
  array(i) = i
end do&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 03:51:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-variable-question/m-p/1550523#M169740</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2023-12-05T03:51:51Z</dc:date>
    </item>
    <item>
      <title>Re: Allocatable variable question</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-variable-question/m-p/1550637#M169754</link>
      <description>&lt;P&gt;Thanks Andrew &amp;amp; Jim,&lt;/P&gt;&lt;P&gt;I vaguely remember Steve Lionel responded to me many years ago to a similar question regarding the allocation of zero sized arrays but I wasn't sure of the context.&amp;nbsp; Having looked further into my code the zero allocated array was being used after all so that was probably the likely cause of the corruption. The program is huge so trying to create a reproducer will take too long and as everything was working fine until I added this new function I think, fingers crossed, the issue should be resolved now.&lt;/P&gt;&lt;P&gt;Thanks again for taking time to reply&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 10:21:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-variable-question/m-p/1550637#M169754</guid>
      <dc:creator>Stephen_Sutcliffe</dc:creator>
      <dc:date>2023-12-05T10:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: Allocatable variable question</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-variable-question/m-p/1551192#M169791</link>
      <description>&lt;P&gt;&amp;gt;&amp;gt;&lt;SPAN&gt;&lt;EM&gt;Having looked further into my code the zero allocated array was being used after all so that was probably the likely cause of the corruption&lt;/EM&gt;.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;If you run your application in Debug mode with all runtime checks (in particular indexing an array out of bounds), this will catch cases where an array, allocated to 0 size, being indexed, will generate a runtime error. And provide you with information as to where this occurred. You can then examine the state of the program to see how you got there. And if necessary, insert some diagnostic code to help insert a proper break point prior to the error condition. This too will help you determine what is happening and lead to a solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 17:49:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-variable-question/m-p/1551192#M169791</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2023-12-06T17:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: Allocatable variable question</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-variable-question/m-p/1551212#M169794</link>
      <description>&lt;P&gt;Thanks Jim,&lt;/P&gt;&lt;P&gt;I did have the array bounds check enabled in debug mode but this didn't flag anything up. I am using whole array methods to copy data rather than indexing so not sure if the checker will detect any issues.&lt;/P&gt;&lt;P&gt;One thing I did notice was that any attempt to allocate anything after the corruption would fail.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just ended up commenting out code where I suspected to problem was and eventually homed in on the zero sized array declaration.&lt;/P&gt;&lt;P&gt;Since making the array a finite size everything has been working fine.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 18:38:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-variable-question/m-p/1551212#M169794</guid>
      <dc:creator>Stephen_Sutcliffe</dc:creator>
      <dc:date>2023-12-06T18:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: Allocatable variable question</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-variable-question/m-p/1551473#M169812</link>
      <description>&lt;P&gt;&amp;gt;&amp;gt;&lt;EM&gt;I am using whole array methods to copy data rather than indexing so not sure if the checker will detect any issues.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Then should the zero length allocatable array be on the LHS it would(should) get reallocated without error (barring allocation failure).&lt;/P&gt;&lt;P&gt;If used on the RHS, then... not sure as to what should happen.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note, there is another post on this forum regarding maxloc and minloc when supplied with a zero length array. The language standard apparently hasn't defined the behavior in this case. I am unaware of what should happen when the LHS is&lt;/P&gt;&lt;P&gt;a) an allocatable array&lt;/P&gt;&lt;P&gt;b) an array with defined size&lt;/P&gt;&lt;P&gt;c) a zero length array.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I suggest you identify the sensitive placed in your code, and write your preference as to what to do in this situation....&lt;/P&gt;&lt;P&gt;Raise an error, use default values, use unusual values, use Signaling NAN's, ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 15:04:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-variable-question/m-p/1551473#M169812</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2023-12-07T15:04:07Z</dc:date>
    </item>
  </channel>
</rss>

