<?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 Module members surprisingly shared through USE statement in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Module-members-surprisingly-shared-through-USE-statement/m-p/816353#M45435</link>
    <description>It is all too easy to "transfer" our knowledge of one language over to another. Some time ago a colleague (used to programming in C)was struggling to debug some code because he came across CHARACTER*(*) X and thought that X was some kind of C pointer to type char or possibly a pointer to pointer to char.&lt;BR /&gt;Ioccasionally make the mistake of writing Fortran syntax (e.g. comments at the end of a line) in C code I'm working on - it makes for interesting compiler messages :-)&lt;BR /&gt;&lt;BR /&gt;Les</description>
    <pubDate>Tue, 28 Sep 2010 14:12:26 GMT</pubDate>
    <dc:creator>Les_Neilson</dc:creator>
    <dc:date>2010-09-28T14:12:26Z</dc:date>
    <item>
      <title>Module members surprisingly shared through USE statement</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Module-members-surprisingly-shared-through-USE-statement/m-p/816349#M45431</link>
      <description>&lt;P&gt;The example below demonstrates how the member&lt;CODE&gt;MY_INT&lt;/CODE&gt; of module A are visible in the main program that doesn't explicitly USE module A. All that is needed is that the program contains statement USE B, and module B contains statement USE A.&lt;/P&gt;&lt;P&gt;Is this as it should be? I find it surprising. In a scenario where I have a low-level module A that module B uses for some dirty implementation details, the low-level stuff from A flows to even higher-level program units unless I pay attention in each module and program to make default visibility PRIVATE. Why should it be so that all the modules that module B uses, are by default used also by those who use module B?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;
MODULE A
   IMPLICIT NONE
   INTEGER :: MY_INT = 42
END MODULE A

MODULE B
   USE A&lt;BR /&gt;&lt;/CODE&gt;&lt;CODE&gt;   IMPLICIT NONE&lt;BR /&gt;   ! PRIVATE ! uncomment this line to make MY_INT not visible to whoever uses this module&lt;BR /&gt;END MODULE B

PROGRAM MODULEUSETEST
   USE B
   IMPLICIT NONE
   WRITE(*,*) MY_INT      ! compiles and prints "42"
END PROGRAM MODULEUSETEST
&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Sep 2010 11:11:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Module-members-surprisingly-shared-through-USE-statement/m-p/816349#M45431</guid>
      <dc:creator>vvnurmi</dc:creator>
      <dc:date>2010-09-28T11:11:20Z</dc:date>
    </item>
    <item>
      <title>Module members surprisingly shared through USE statement</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Module-members-surprisingly-shared-through-USE-statement/m-p/816350#M45432</link>
      <description>&lt;I&gt;Is this as it should be? I find it surprising.&lt;BR /&gt;&lt;BR /&gt;&lt;/I&gt;Of course it is. A perusal of the Fortran documentation, or textbooks on modern Fortran, would remove the surprise.&lt;BR /&gt;&lt;BR /&gt;USE means "use as prescribed by the rules". It cannot mean "use only those things that I want and leave out those that I don't want but, as I am too busy to specify them in writing, figure it out yourself." This is so, just as IMPLICIT NONE implies that within its scope &lt;SPAN style="text-decoration: underline;"&gt;all&lt;/SPAN&gt; undeclared variables are illegal, even the name/prefix BOOL that I always use for my logical variables.&lt;BR /&gt;&lt;BR /&gt;Compilers are not yet mind readers, and I am content with that state of affairs.</description>
      <pubDate>Tue, 28 Sep 2010 11:47:39 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Module-members-surprisingly-shared-through-USE-statement/m-p/816350#M45432</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2010-09-28T11:47:39Z</dc:date>
    </item>
    <item>
      <title>Module members surprisingly shared through USE statement</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Module-members-surprisingly-shared-through-USE-statement/m-p/816351#M45433</link>
      <description>I guess in order for a module to be useful, it needs to have at least one publicly accessible entity. That, plus the fact that modules sort of grew out of include files, tends to point towards public accessibility being the default. Once you are there, having use associated entities somehow behave differently to other entities in the module (in the absence of some mechanism that specifies accessibility for all entities picked up from a module - say via attributes on the use statements themselves) would get confusing and I can think of some cases where it could create maintenance headaches.&lt;BR /&gt;&lt;BR /&gt;You could also add a PRIVATE :: MY_INT statement to module B.&lt;BR /&gt;&lt;BR /&gt;Most of my modules have private accessibility as the default. If you are trying to hide implementation this is the easiest thing to do anyway. Of course, until submodules are here there's nothing to stop the inquisitive client programmer from putting USE A into the main program and accessing MY_INT that way.</description>
      <pubDate>Tue, 28 Sep 2010 12:20:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Module-members-surprisingly-shared-through-USE-statement/m-p/816351#M45433</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2010-09-28T12:20:44Z</dc:date>
    </item>
    <item>
      <title>Module members surprisingly shared through USE statement</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Module-members-surprisingly-shared-through-USE-statement/m-p/816352#M45434</link>
      <description>&lt;P&gt;&lt;EM&gt;Of course it is. A perusal of the Fortran documentation, or textbooks on modern Fortran, would remove the surprise.&lt;/EM&gt;&lt;EM&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;I failed to find an exhaustive explanation of this with moderate effort from my Fortran textbook. Knowing now that this is an intended feature of Fortran, there is no surprise any longer.&lt;/P&gt;&lt;P&gt;I originally thought Fortran's USE to behave more like "using" in C# or "import" in Java, importing symbols only for use at the local context but not any further. This serves as a good lesson to find out the facts before assuming anything :-).&lt;/P&gt;&lt;P&gt;Thanks for the help.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Sep 2010 13:54:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Module-members-surprisingly-shared-through-USE-statement/m-p/816352#M45434</guid>
      <dc:creator>vvnurmi</dc:creator>
      <dc:date>2010-09-28T13:54:31Z</dc:date>
    </item>
    <item>
      <title>Module members surprisingly shared through USE statement</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Module-members-surprisingly-shared-through-USE-statement/m-p/816353#M45435</link>
      <description>It is all too easy to "transfer" our knowledge of one language over to another. Some time ago a colleague (used to programming in C)was struggling to debug some code because he came across CHARACTER*(*) X and thought that X was some kind of C pointer to type char or possibly a pointer to pointer to char.&lt;BR /&gt;Ioccasionally make the mistake of writing Fortran syntax (e.g. comments at the end of a line) in C code I'm working on - it makes for interesting compiler messages :-)&lt;BR /&gt;&lt;BR /&gt;Les</description>
      <pubDate>Tue, 28 Sep 2010 14:12:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Module-members-surprisingly-shared-through-USE-statement/m-p/816353#M45435</guid>
      <dc:creator>Les_Neilson</dc:creator>
      <dc:date>2010-09-28T14:12:26Z</dc:date>
    </item>
    <item>
      <title>Module members surprisingly shared through USE statement</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Module-members-surprisingly-shared-through-USE-statement/m-p/816354#M45436</link>
      <description>Section 5.15 of &lt;I&gt;Fortran 95/2003 explained&lt;/I&gt; by Metcalf, Reid and Cohen, Oxford, 2005, says:&lt;BR /&gt;&lt;I&gt;&lt;BR /&gt;--------------------------------&lt;BR /&gt;&lt;/I&gt;5.15 Scope of Names&lt;BR /&gt;..&lt;BR /&gt;A &lt;B&gt;use&lt;/B&gt; statement of the form&lt;BR /&gt;&lt;BR /&gt; &lt;B&gt;use&lt;/B&gt; &lt;I&gt;module-name&lt;/I&gt;&lt;BR /&gt;&lt;BR /&gt;is regarded as a re-declaration of all the module entities inside the local scoping unit, with exactly the same names and properties.&lt;BR /&gt;---------------------------------&lt;BR /&gt;&lt;BR /&gt;One large package in Fortran that I saw a few months ago made effective use of the properties of modules in the following way. &lt;BR /&gt;&lt;BR /&gt;There was a module-A which contained declarations of all variables which were shared across subprograms in the package. However, no subprogram USEd module-A directly. &lt;BR /&gt;&lt;BR /&gt;Instead, there were modules B1, B2, B3,.., all of which USEd module-A, but used the &lt;B&gt;use module-A, only:&lt;/B&gt; ... in combination with &lt;B&gt;private&lt;/B&gt; applied to the variables brought in this way. Thus, the programmer provided controlled access to only those variables that were actually needed in each subprogram, avoiding unwanted exposure of the other variables in module-A. &lt;BR /&gt;&lt;BR /&gt;The subprograms, in turn, USEd modules B1, B2, ...., thus gaining access to &lt;SPAN style="text-decoration: underline;"&gt;only&lt;/SPAN&gt; those parts of module-A that they were entitled to.&lt;BR /&gt;</description>
      <pubDate>Tue, 28 Sep 2010 15:29:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Module-members-surprisingly-shared-through-USE-statement/m-p/816354#M45436</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2010-09-28T15:29:36Z</dc:date>
    </item>
  </channel>
</rss>

