<?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: Fortran -e03 not giving warning for C_LOC and character str in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-e03-not-giving-warning-for-C-LOC-and-character-strings/m-p/749260#M6208</link>
    <description>Exactly, this code is standard compliant:&lt;BR /&gt;&lt;BR /&gt;MODULE modtest&lt;BR /&gt; USE ISO_C_BINDING&lt;BR /&gt;CONTAINS&lt;BR /&gt; SUBROUTINE One( chr )&lt;BR /&gt; CHARACTER(LEN=1, KIND=C_CHAR), DIMENSION(*), TARGET :: chr&lt;BR /&gt; TYPE(C_PTR) :: chr_ptr&lt;BR /&gt; chr_ptr = C_LOC(chr)&lt;BR /&gt; END SUBROUTINE One&lt;BR /&gt;END MODULE modtest&lt;BR /&gt;&lt;BR /&gt;PROGRAM main&lt;BR /&gt; USE ISO_C_BINDING&lt;BR /&gt; USE modtest&lt;BR /&gt; CHARACTER(LEN=8, KIND=C_CHAR), DIMENSION(1:4) :: chr&lt;BR /&gt; chr(1) = '00000001'&lt;BR /&gt; chr(2) = '00000002'&lt;BR /&gt; chr(3) = '00000003'&lt;BR /&gt; chr(4) = '00000004'&lt;BR /&gt; CALL One( chr )&lt;BR /&gt;END PROGRAM main&lt;BR /&gt;&lt;BR /&gt;BUT, say you add a generic interface and have a multi-dimension array of character strings of size&amp;gt;1, then we see the problem with passing a character string with length X into a dummy character argument array LEN=1 but of size X, for example:&lt;BR /&gt;&lt;BR /&gt;MODULE modtest&lt;BR /&gt; USE ISO_C_BINDING&lt;BR /&gt; INTERFACE One&lt;BR /&gt; MODULE PROCEDURE Two&lt;BR /&gt; END INTERFACE&lt;BR /&gt;CONTAINS&lt;BR /&gt; SUBROUTINE Two( chr )&lt;BR /&gt; CHARACTER(LEN=1, KIND=C_CHAR), DIMENSION(*), TARGET :: chr&lt;BR /&gt; TYPE(C_PTR) :: chr_ptr&lt;BR /&gt; chr_ptr = C_LOC(chr)&lt;BR /&gt; END SUBROUTINE Two&lt;BR /&gt;END MODULE modtest&lt;BR /&gt;&lt;BR /&gt;PROGRAM main&lt;BR /&gt; USE ISO_C_BINDING&lt;BR /&gt; USE modtest&lt;BR /&gt;&lt;BR /&gt; CHARACTER(LEN=8, KIND=C_CHAR), DIMENSION(1:4) :: chr&lt;BR /&gt; CHARACTER(LEN=2, KIND=C_CHAR), DIMENSION(1:4, 1:4) :: chr2&lt;BR /&gt;&lt;BR /&gt; chr(1) = '00000001'&lt;BR /&gt; chr(2) = '00000002'&lt;BR /&gt; chr(3) = '00000003'&lt;BR /&gt; chr(4) = '00000004'&lt;BR /&gt;&lt;BR /&gt; chr2(1,:) = '01'&lt;BR /&gt; chr2(2,:) = '02'&lt;BR /&gt; chr2(3,:) = '03'&lt;BR /&gt; chr2(4,:) = '04'&lt;BR /&gt;&lt;BR /&gt; CALL One( chr2 )&lt;BR /&gt;&lt;BR /&gt;END PROGRAM main&lt;BR /&gt;&lt;BR /&gt;Now the compiler will not see an interface for One(chr2), but if you were to just &lt;BR /&gt;&lt;BR /&gt;CALL Two(chr2) &lt;BR /&gt;&lt;BR /&gt;instead it will work fine.&lt;BR /&gt;&lt;BR /&gt;For higher order arrays you would have to add another routine for each dimension of the array you added up to 7 times if needed, not very elegant:&lt;BR /&gt;&lt;BR /&gt; SUBROUTINE Three( chr, ndim1 )&lt;BR /&gt; CHARACTER(LEN=1, KIND=C_CHAR), DIMENSION(ndim1,*), TARGET :: chr&lt;BR /&gt; TYPE(C_PTR) :: chr_ptr&lt;BR /&gt; chr_ptr = C_LOC(chr)&lt;BR /&gt; END SUBROUTINE Three&lt;BR /&gt;&lt;BR /&gt;Thankfully some compilers have extended the standard to LEN&amp;gt;1.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Wed, 09 Jul 2008 20:22:36 GMT</pubDate>
    <dc:creator>breitenfeld</dc:creator>
    <dc:date>2008-07-09T20:22:36Z</dc:date>
    <item>
      <title>Fortran -e03 not giving warning for C_LOC and character strings</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-e03-not-giving-warning-for-C-LOC-and-character-strings/m-p/749258#M6206</link>
      <description>I have a question as to why, when I compile (using 10.1) the following code with ifort -e03, the compiler does not give a warning:&lt;BR /&gt;&lt;BR /&gt;PROGRAM main&lt;BR /&gt; USE ISO_C_BINDING&lt;BR /&gt; CHARACTER(LEN=2, KIND=C_CHAR), TARGET :: chr&lt;BR /&gt; TYPE(C_PTR) :: chr_ptr&lt;BR /&gt; chr_ptr = C_LOC(chr)&lt;BR /&gt;END PROGRAM main&lt;BR /&gt;&lt;BR /&gt;For the C_LOC(X) function X must be interpretable and for a character the standard says:&lt;BR /&gt;&lt;BR /&gt;15.2.1 Interoperability of intrinsic types&lt;BR /&gt;3 Table 15.2 shows the interoperability between Fortran intrinsic types and C types. A Fortran intrinsic&lt;BR /&gt;4 type with particular type parameter values is interoperable with a C type if the type and kind type&lt;BR /&gt;5 parameter value are listed in the table on the same row as that C type; if the type is character, inter&lt;BR /&gt;6 operability also requires that the length type parameter be omitted or be specified by an initialization&lt;BR /&gt;7 expression whose value is one.&lt;BR /&gt;&lt;BR /&gt;so doesn't the standard require&lt;BR /&gt;&lt;BR /&gt;CHARACTER(LEN=1, KIND=C_CHAR), TARGET :: chr(2)&lt;BR /&gt;or&lt;BR /&gt;CHARACTER(KIND=C_CHAR), TARGET :: chr(2)&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 08 Jul 2008 16:11:11 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-e03-not-giving-warning-for-C-LOC-and-character-strings/m-p/749258#M6206</guid>
      <dc:creator>breitenfeld</dc:creator>
      <dc:date>2008-07-08T16:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: Fortran -e03 not giving warning for C_LOC and character str</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-e03-not-giving-warning-for-C-LOC-and-character-strings/m-p/749259#M6207</link>
      <description>I'm inclined to agree with you. There's an interesting side-issue that a CHARACTER(2) actual argument is allowed to match a CHARACTER(1,KIND=C_CHAR), DIMENSION(2) dummy argument (12.4.1.2). I'll let the developers know about this.&lt;BR /&gt;</description>
      <pubDate>Tue, 08 Jul 2008 17:24:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-e03-not-giving-warning-for-C-LOC-and-character-strings/m-p/749259#M6207</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2008-07-08T17:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: Fortran -e03 not giving warning for C_LOC and character str</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-e03-not-giving-warning-for-C-LOC-and-character-strings/m-p/749260#M6208</link>
      <description>Exactly, this code is standard compliant:&lt;BR /&gt;&lt;BR /&gt;MODULE modtest&lt;BR /&gt; USE ISO_C_BINDING&lt;BR /&gt;CONTAINS&lt;BR /&gt; SUBROUTINE One( chr )&lt;BR /&gt; CHARACTER(LEN=1, KIND=C_CHAR), DIMENSION(*), TARGET :: chr&lt;BR /&gt; TYPE(C_PTR) :: chr_ptr&lt;BR /&gt; chr_ptr = C_LOC(chr)&lt;BR /&gt; END SUBROUTINE One&lt;BR /&gt;END MODULE modtest&lt;BR /&gt;&lt;BR /&gt;PROGRAM main&lt;BR /&gt; USE ISO_C_BINDING&lt;BR /&gt; USE modtest&lt;BR /&gt; CHARACTER(LEN=8, KIND=C_CHAR), DIMENSION(1:4) :: chr&lt;BR /&gt; chr(1) = '00000001'&lt;BR /&gt; chr(2) = '00000002'&lt;BR /&gt; chr(3) = '00000003'&lt;BR /&gt; chr(4) = '00000004'&lt;BR /&gt; CALL One( chr )&lt;BR /&gt;END PROGRAM main&lt;BR /&gt;&lt;BR /&gt;BUT, say you add a generic interface and have a multi-dimension array of character strings of size&amp;gt;1, then we see the problem with passing a character string with length X into a dummy character argument array LEN=1 but of size X, for example:&lt;BR /&gt;&lt;BR /&gt;MODULE modtest&lt;BR /&gt; USE ISO_C_BINDING&lt;BR /&gt; INTERFACE One&lt;BR /&gt; MODULE PROCEDURE Two&lt;BR /&gt; END INTERFACE&lt;BR /&gt;CONTAINS&lt;BR /&gt; SUBROUTINE Two( chr )&lt;BR /&gt; CHARACTER(LEN=1, KIND=C_CHAR), DIMENSION(*), TARGET :: chr&lt;BR /&gt; TYPE(C_PTR) :: chr_ptr&lt;BR /&gt; chr_ptr = C_LOC(chr)&lt;BR /&gt; END SUBROUTINE Two&lt;BR /&gt;END MODULE modtest&lt;BR /&gt;&lt;BR /&gt;PROGRAM main&lt;BR /&gt; USE ISO_C_BINDING&lt;BR /&gt; USE modtest&lt;BR /&gt;&lt;BR /&gt; CHARACTER(LEN=8, KIND=C_CHAR), DIMENSION(1:4) :: chr&lt;BR /&gt; CHARACTER(LEN=2, KIND=C_CHAR), DIMENSION(1:4, 1:4) :: chr2&lt;BR /&gt;&lt;BR /&gt; chr(1) = '00000001'&lt;BR /&gt; chr(2) = '00000002'&lt;BR /&gt; chr(3) = '00000003'&lt;BR /&gt; chr(4) = '00000004'&lt;BR /&gt;&lt;BR /&gt; chr2(1,:) = '01'&lt;BR /&gt; chr2(2,:) = '02'&lt;BR /&gt; chr2(3,:) = '03'&lt;BR /&gt; chr2(4,:) = '04'&lt;BR /&gt;&lt;BR /&gt; CALL One( chr2 )&lt;BR /&gt;&lt;BR /&gt;END PROGRAM main&lt;BR /&gt;&lt;BR /&gt;Now the compiler will not see an interface for One(chr2), but if you were to just &lt;BR /&gt;&lt;BR /&gt;CALL Two(chr2) &lt;BR /&gt;&lt;BR /&gt;instead it will work fine.&lt;BR /&gt;&lt;BR /&gt;For higher order arrays you would have to add another routine for each dimension of the array you added up to 7 times if needed, not very elegant:&lt;BR /&gt;&lt;BR /&gt; SUBROUTINE Three( chr, ndim1 )&lt;BR /&gt; CHARACTER(LEN=1, KIND=C_CHAR), DIMENSION(ndim1,*), TARGET :: chr&lt;BR /&gt; TYPE(C_PTR) :: chr_ptr&lt;BR /&gt; chr_ptr = C_LOC(chr)&lt;BR /&gt; END SUBROUTINE Three&lt;BR /&gt;&lt;BR /&gt;Thankfully some compilers have extended the standard to LEN&amp;gt;1.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 09 Jul 2008 20:22:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-e03-not-giving-warning-for-C-LOC-and-character-strings/m-p/749260#M6208</guid>
      <dc:creator>breitenfeld</dc:creator>
      <dc:date>2008-07-09T20:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: Fortran -e03 not giving warning for C_LOC and character str</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-e03-not-giving-warning-for-C-LOC-and-character-strings/m-p/749261#M6209</link>
      <description>I believe that the compiler is not required to give a standards diagnostic in this case, as the rule being violated is neither a numbered syntax rule nor a constraint. It is the requirement on the programmer to comply with the stated rule. Given the way intrinsic modules are defined in the standard, it may not be feasible to diagnose such violations.&lt;BR /&gt;</description>
      <pubDate>Wed, 09 Jul 2008 21:01:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-e03-not-giving-warning-for-C-LOC-and-character-strings/m-p/749261#M6209</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2008-07-09T21:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: Fortran -e03 not giving warning for C_LOC and character str</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-e03-not-giving-warning-for-C-LOC-and-character-strings/m-p/749262#M6210</link>
      <description>The developers agree with my last statement. Diagnosis of this is not required by the standard, and since C_LOC is a module procedure and not an intrinsic procedure, we don't even have a good way of detecting this misuse. It is incumbent on the programmer to follow the rule - we're not going to try to check for it.&lt;BR /&gt;</description>
      <pubDate>Fri, 11 Jul 2008 19:28:01 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-e03-not-giving-warning-for-C-LOC-and-character-strings/m-p/749262#M6210</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2008-07-11T19:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Fortran -e03 not giving warning for C_LOC and character str</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-e03-not-giving-warning-for-C-LOC-and-character-strings/m-p/749263#M6211</link>
      <description>I'm assuming that your last 2 comments are in regards to my second reply in this thread. &lt;BR /&gt;&lt;BR /&gt;The following code to me looks to be standard compliant, as you mentioned the CHARACTER(LEN=4) actual argument is
allowed to match a CHARACTER(LEN=1,KIND=C_CHAR), DIMENSION(4) dummy
argument (12.4.1.2). But the compiler will not recognize subroutine 'Two' as a valid interface for the call indicated. So if you are going by the standard you can not use a generic interface to handle a scalar character (len&amp;gt;1) and an array of characters (keeping in mind that all the subroutines have to have LEN=1 so that you can use C_LOC). That is why I really appreciate intel (among others) extending the standard such that C_LOC(X) can accept character X with LEN&amp;gt;1.&lt;BR /&gt;&lt;BR /&gt;MODULE modtest&lt;BR /&gt;&lt;BR /&gt; USE ISO_C_BINDING&lt;BR /&gt;&lt;BR /&gt; INTERFACE One&lt;BR /&gt; MODULE PROCEDURE Two&lt;BR /&gt; END INTERFACE&lt;BR /&gt;&lt;BR /&gt;CONTAINS&lt;BR /&gt; SUBROUTINE Two( chr )&lt;BR /&gt; CHARACTER(LEN=1, KIND=C_CHAR), DIMENSION(1:4) :: chr&lt;BR /&gt; PRINT*,chr(1:4)&lt;BR /&gt; END SUBROUTINE Two&lt;BR /&gt;END MODULE modtest&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;PROGRAM main&lt;BR /&gt; USE ISO_C_BINDING&lt;BR /&gt; USE modtest&lt;BR /&gt;&lt;BR /&gt; CHARACTER(LEN=4, KIND=C_CHAR) :: chrScalar&lt;BR /&gt; chrScalar = 'Scal'&lt;BR /&gt;&lt;BR /&gt;! This does not work&lt;BR /&gt;&lt;BR /&gt; CALL One( chrScalar )&lt;BR /&gt;&lt;BR /&gt;! This works&lt;BR /&gt;&lt;BR /&gt; CALL Two( chrScalar )&lt;BR /&gt;&lt;BR /&gt;END PROGRAM main&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 11 Jul 2008 20:36:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-e03-not-giving-warning-for-C-LOC-and-character-strings/m-p/749263#M6211</guid>
      <dc:creator>breitenfeld</dc:creator>
      <dc:date>2008-07-11T20:36:55Z</dc:date>
    </item>
    <item>
      <title>Re: Fortran -e03 not giving warning for C_LOC and character str</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-e03-not-giving-warning-for-C-LOC-and-character-strings/m-p/749264#M6212</link>
      <description>My last two comments were regarding your initial issue about C_LOC. I would not say that we "extended the standard", but rather don't have a good way of enforcing the standard's requirement of an interoperable type.&lt;BR /&gt;&lt;BR /&gt;Unfortunately, generic resolution does not seem to have been extended to allow for what you want. It strictly requires "TKR" (Type, Kind and Rank) match. You might need a jacket routine that in turn calls the C routine with the C_CHAR interface.&lt;BR /&gt;</description>
      <pubDate>Fri, 11 Jul 2008 21:42:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-e03-not-giving-warning-for-C-LOC-and-character-strings/m-p/749264#M6212</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2008-07-11T21:42:26Z</dc:date>
    </item>
  </channel>
</rss>

