<?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 #18, the one above mine. in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144688#M138180</link>
    <description>&lt;P&gt;#18, the one above mine.&lt;/P&gt;</description>
    <pubDate>Thu, 22 Aug 2019 23:05:02 GMT</pubDate>
    <dc:creator>gib</dc:creator>
    <dc:date>2019-08-22T23:05:02Z</dc:date>
    <item>
      <title>New Interoperability: Fortran to C++ (String case)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144668#M138160</link>
      <description>&lt;P&gt;I would like to send a Fortran string&amp;nbsp;to my C++ application, I tried to to this,&amp;nbsp;&lt;STRONG&gt;but I got this linker error:&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE class="brush:bash; class-name:dark;"&gt;unresolved external symbol for_cpystr referenced in function my_long_calc&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;My Fortran Static Lib Code (Visual Fortran):&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE class="brush:fortran; class-name:dark;"&gt;module my_interfaces
&amp;nbsp; &amp;nbsp; use iso_c_binding
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; interface
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; subroutine fortran_message(msg) bind(C, name = 'fortran_message')
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; use, intrinsic :: iso_c_binding
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; character(kind = c_char), dimension(*), intent(out) :: msg
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end subroutine fortran_message
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end interface
end module my_interfaces

! My long calc subroutine
subroutine my_long_calc() BIND(C, name = 'my_long_calc')
&amp;nbsp; &amp;nbsp; use, intrinsic :: ISO_C_BINDING
&amp;nbsp; &amp;nbsp; use my_interfaces
&amp;nbsp; &amp;nbsp; implicit none
&amp;nbsp; &amp;nbsp;&amp;nbsp;
&amp;nbsp; &amp;nbsp; ! A single variable:
&amp;nbsp; &amp;nbsp; character(len = 40, kind = c_char) :: msg
&amp;nbsp; &amp;nbsp;&amp;nbsp;
&amp;nbsp; &amp;nbsp; msg = "this is a msg from fortran"
&amp;nbsp; &amp;nbsp;&amp;nbsp;
&amp;nbsp; &amp;nbsp; ! Send a message to the C++ application:
&amp;nbsp; &amp;nbsp; call fortran_message(msg)
end subroutine my_long_calc&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;My C++ Code:&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:cpp; class-name:dark;"&gt;#include &amp;lt;iostream&amp;gt;

extern "C" {
  void my_long_calc(void);
  void fortran_message(char* msg);
}

void fortran_message(char* msg)
{
  std::cout &amp;lt;&amp;lt; *msg &amp;lt;&amp;lt; std::endl;
}

int main(int argc, char *argv[])
{
    my_long_calc();

    return 0;
}
&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Please, what I have to do to link this library and get the "msg" string inside the C++ application?&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2019 20:07:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144668#M138160</guid>
      <dc:creator>Maia__Nycholas</dc:creator>
      <dc:date>2019-08-13T20:07:40Z</dc:date>
    </item>
    <item>
      <title>Two things:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144669#M138161</link>
      <description>&lt;P&gt;Two things:&lt;/P&gt;&lt;P&gt;In the Fortran code, you have to NUL-terminate the string:&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;msg = "this is a msg from fortran"//C_NULL_CHAR&lt;/PRE&gt;

&lt;P&gt;In the C++ code, you have an extra level of indirection. Remove the * in *msg in the output line, like so:&lt;/P&gt;

&lt;PRE class="brush:cpp; class-name:dark;"&gt;std::cout &amp;lt;&amp;lt; msg &amp;lt;&amp;lt; std::endl;&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2019 20:44:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144669#M138161</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2019-08-13T20:44:51Z</dc:date>
    </item>
    <item>
      <title>See your other thread, Quote</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144670#M138162</link>
      <description>&lt;P&gt;See your other thread, Quote #8:&lt;/P&gt;&lt;P&gt;&lt;A href="https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/815889" target="_blank"&gt;https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/815889&lt;/A&gt;&lt;/P&gt;&lt;P&gt;While passing "string" data from/to Fortran with other languages such as C++,&amp;nbsp; passing the string length&amp;nbsp;as shown can simplify the&amp;nbsp;interoperation considerably.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 02:40:42 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144670#M138162</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2019-08-14T02:40:42Z</dc:date>
    </item>
    <item>
      <title>@Steve, thanks for your quick</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144671#M138163</link>
      <description>&lt;P&gt;@Steve, thanks for your quick response...&lt;BR /&gt;&lt;BR /&gt;I did the 2 things that you propose to me, &lt;STRONG&gt;but I got the same error yet.&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE class="brush:bash; class-name:dark;"&gt;unresolved external symbol for_cpystr referenced in function my_long_calc&lt;/PRE&gt;

&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;My modified Fortran Code:&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:fortran; class-name:dark;"&gt;module my_interfaces
    use iso_c_binding
        interface
            subroutine fortran_message(msg) bind(C, name = 'fortran_message')
                use, intrinsic :: iso_c_binding
                
                character(kind = c_char), dimension(*), intent(out) :: msg
                
            end subroutine fortran_message
        end interface
end module my_interfaces

! My long calc subroutine
subroutine my_long_calc() BIND(C, name = 'my_long_calc')
    use, intrinsic :: ISO_C_BINDING
    use my_interfaces
    implicit none
    
    ! A single variable:
    character(len = 40, kind = c_char) :: msg
    
    msg = "this is a msg from fortran"//C_NULL_CHAR
    
    ! Send a message to the C++ application:
    call fortran_message(msg)
end subroutine my_long_calc&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;My modified C++ code:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE class="brush:cpp; class-name:dark;"&gt;#include &amp;lt;iostream&amp;gt;

extern "C" {
    void my_long_calc(void);
    void fortran_message(char* msg);
}

void fortran_message(char* msg)
{
    std::cout &amp;lt;&amp;lt; msg &amp;lt;&amp;lt; std::endl;
}

int main(void)
{
    my_long_calc();

    return 0;
}&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Could you help me again?&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;In this small example, I'm trying to get a simple string from fortran to C++....&lt;STRONG&gt;but if you are can make me one additional favor, &lt;/STRONG&gt;my goal is to send 1 integer value argument and 2 independent strings (the string size can be&amp;nbsp;constant) from fortran to C++.&lt;STRONG&gt; Is it possible?&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;I think that my C++ header could be:&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:cpp; class-name:dark;"&gt;void fortran_message(int* value, char* msg1, size_t* len1, char* msg2, size_t* len2)&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;That´s it?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Thank you again,&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 13:26:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144671#M138163</guid>
      <dc:creator>Maia__Nycholas</dc:creator>
      <dc:date>2019-08-14T13:26:00Z</dc:date>
    </item>
    <item>
      <title>You will need to link in the</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144672#M138164</link>
      <description>&lt;P&gt;You will need to link in the Fortran support libraries. If you are using Intel Fortran and Visual Studio, see&amp;nbsp;https://software.intel.com/en-us/articles/configuring-visual-studio-for-mixed-language-applications&lt;/P&gt;&lt;P&gt;The interface for your revised fortran_message function would be:&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;interface
  subroutine fortran_message (value, msg1, len1, msg2, len2) bind(C)
    use, intrinsic :: ISO_C_BINDING
    integer(C_INT), intent(in) :: value
    character(kind=C_CHAR), intent(in) :: msg1(*)
    integer(C_SIZE_T), intent(in) :: len1
    character(kind=C_CHAR), intent(in) :: msg2(*)
    integer(C_SIZE_T), intent(in) :: len2
  end subroutine fortran_message
end interface&lt;/PRE&gt;

&lt;P&gt;You will, of course, need to pass the lengths separately. I might suggest that it is actually easier to nul-terminate the strings than pass the lengths. If you pass lengths you will need to change the C++ code, and I don't know what that change would be (I am not a C++ programmer - I can stumble around in C.)&lt;/P&gt;
&lt;P&gt;You might also choose to pass the lengths by value (size_t instead of size_t*). If so, add the VALUE attribute to those arguments in the Fortran interface. (I will comment that VALUE changes its meaning when you add BIND(C) to the interface or procedure. For a BIND(C) routine it means what you would expect - pass by value. Otherwise it means "pass a writable, anonymous copy".)&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 14:20:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144672#M138164</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2019-08-14T14:20:30Z</dc:date>
    </item>
    <item>
      <title>@Thank Steve, I think that we</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144673#M138165</link>
      <description>&lt;P&gt;@Thank Steve, I think that&lt;STRONG&gt; we are close&lt;/STRONG&gt; to the perfect linking process...&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;2 things:&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;First:&lt;/STRONG&gt; Thanks for your sugestion about not pass the lenghts of the string. Yes,&lt;STRONG&gt; I would like to pass only the string itself.&lt;/STRONG&gt;&lt;BR /&gt;I undertand that C++ is not your main language, but could you show me how will be this "print&amp;nbsp;string function" &lt;STRONG&gt;using&amp;nbsp;pure C?&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Second: &lt;/STRONG&gt;Trying to solve the linker error above, I added to my compile command line (using QT Creator IDE) all the Intel Visual Fortran "include" and "library"&amp;nbsp;folders tha&lt;STRONG&gt;t Microsoft Visual Studio 2019 are using inside of itself.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I looked at: Visual Studio 2019 -&amp;gt; Tools menu -&amp;gt; Options -&amp;gt; Intel Compilers and Tools -&amp;gt; Visual Fortran -&amp;gt; Compilers -&amp;gt; x64 (tab)&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="ivf.jpg"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/10524i211C508A6A8CC4C5/image-size/large?v=v2&amp;amp;px=999&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="ivf.jpg" alt="ivf.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I expand each VS macro and I got this:&lt;BR /&gt;&lt;STRONG&gt;Includes:&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="brush:bash; class-name:dark;"&gt;C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/um&amp;nbsp;
C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/shared&amp;nbsp;
C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019/windows/compiler/include
C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019/windows/compiler/include/Intel64&amp;nbsp;
C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019/windows/mkl/include&amp;nbsp;
C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/VC/VC/Tools/MSVC/14.21.27702/atlmfc/include&amp;nbsp;
C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/VC/PlatformSDK/include/um&amp;nbsp;
C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/VC/PlatformSDK/include/shared&amp;nbsp;
C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/VC/PlatformSDK/include&amp;nbsp;
C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/VC/VC/Tools/MSVC/14.21.27702/lib/x64&amp;nbsp;
C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/um/x64&amp;nbsp;
C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/ucrt/x64&amp;nbsp;
C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019/windows/compiler/lib/Intel64_win&amp;nbsp;
C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019/windows/mkl/lib/Intel64_win&amp;nbsp;
C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/VC/VC/Tools/MSVC/14.21.27702/atlmfc/lib/x64&amp;nbsp;
C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/VC/PlatformSDK/lib/winv6.3/um/x64&lt;/PRE&gt;

&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Libraries:&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:bash; class-name:dark;"&gt;C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/VC/VC/Tools/MSVC/14.21.27702/lib/x64&amp;nbsp;
C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/um/x64&amp;nbsp;
C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/ucrt/x64&amp;nbsp;
C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019/windows/compiler/lib/Intel64_win&amp;nbsp;
C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019/windows/mkl/lib/Intel64_win&amp;nbsp;
C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/VC/VC/Tools/MSVC/14.21.27702/atlmfc/lib/x64&amp;nbsp;
C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/VC/PlatformSDK/lib/winv6.3/um/x64&lt;/PRE&gt;

&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Inside QT Creator IDE (Windows 10 x64), &lt;STRONG&gt;my compiler is Microsoft Visual C++ 16.1&lt;/STRONG&gt;, so my Intel Visual Fortran static library should be compatible, &lt;STRONG&gt;right?&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;But I got the same linker error:&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:bash; class-name:dark;"&gt;unresolved external symbol for_cpystr referenced in function my_long_calc&lt;/PRE&gt;

&lt;P&gt;Maybe should I need to pass each IVF library file to my compile command line? I don't know...And, if yes, &lt;STRONG&gt;how can I know which library?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Could you help me a little bit more?&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 18:16:22 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144673#M138165</guid>
      <dc:creator>Maia__Nycholas</dc:creator>
      <dc:date>2019-08-14T18:16:22Z</dc:date>
    </item>
    <item>
      <title>UPDATE:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144674#M138166</link>
      <description>&lt;P&gt;UPDATE:&lt;BR /&gt;&lt;BR /&gt;Inside Visual Fortran project now I set the "Disable Default Library Search Rules" to NO...and I passed the linker error above.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="ivf.jpg"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/10525i862923A721C126F5/image-size/large?v=v2&amp;amp;px=999&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="ivf.jpg" alt="ivf.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Now, the QT Creator IDE gives me a error about "ia32" folder&amp;nbsp;....I found this ia32 folder and added it in the QT Creator libraries path.&lt;BR /&gt;So, the error now is:&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="brush:bash; class-name:dark;"&gt;error: LNK1181: cannot open input file 'debug\.obj'&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;What I have to do now?&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 18:37:06 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144674#M138166</guid>
      <dc:creator>Maia__Nycholas</dc:creator>
      <dc:date>2019-08-14T18:37:06Z</dc:date>
    </item>
    <item>
      <title>UPDATE 2:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144675#M138167</link>
      <description>&lt;P&gt;UPDATE 2:&lt;BR /&gt;&lt;BR /&gt;I closed QT Creator IDE &lt;STRONG&gt;and cleaned all temp files...&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;Open it again and tried to compile/link my project. So, I got:&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="brush:bash; class-name:dark;"&gt;LNK1104: cannot open file 'C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2019.4.245\windows\compiler\lib\ia32_win.obj'&lt;/PRE&gt;

&lt;P&gt;First the linker asked me about "ifconsol.lib"...then I added the path to this lib:&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:bash; class-name:dark;"&gt;C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2019.4.245\windows\compiler\lib\ia32_win&lt;/PRE&gt;

&lt;P&gt;Now it is asking about a *.obj file? &lt;STRONG&gt;What is wrong?&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 19:00:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144675#M138167</guid>
      <dc:creator>Maia__Nycholas</dc:creator>
      <dc:date>2019-08-14T19:00:19Z</dc:date>
    </item>
    <item>
      <title>UPDATE 3: Almost there!</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144676#M138168</link>
      <description>&lt;P&gt;&lt;STRONG&gt;UPDATE 3: Almost there!&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;@Steve, I finally got the Fortran string in my C++ application, but the string are just &lt;STRONG&gt;the first character repeating multiple times...&lt;/STRONG&gt;&lt;BR /&gt;Please, if you could look my code again, I think that will be that last post of this topic.&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;My Fortran Code:&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;module my_interfaces
interface
  subroutine fortran_message (value, msg1, len1, msg2, len2) bind(C)
    use, intrinsic :: ISO_C_BINDING
    integer(C_INT), intent(in) :: value
    character(kind=C_CHAR), intent(in) :: msg1(*)
    integer(C_SIZE_T), intent(in) :: len1
    character(kind=C_CHAR), intent(in) :: msg2(*)
    integer(C_SIZE_T), intent(in) :: len2
  end subroutine fortran_message
end interface
end module my_interfaces

! My long calc subroutine
subroutine my_long_calc() BIND(C, name = 'my_long_calc')
    use, intrinsic :: ISO_C_BINDING
    use my_interfaces
    implicit none
    
    integer(C_INT) :: value
    character(kind=C_CHAR) :: msg1(5)
    integer(C_SIZE_T) :: len1
    character(kind=C_CHAR) :: msg2(5)
    integer(C_SIZE_T) :: len2
    
    value = 10
    msg1 = "nyck"//C_NULL_CHAR
    len1 = 5
    msg2 = "sara"//C_NULL_CHAR
    len2 = 5
    
    ! Send a message to the C++ application:
    call fortran_message(value, msg1, len1, msg2, len2)
end subroutine my_long_calc&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;My C++ code:&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:cpp; class-name:dark;"&gt;#include &amp;lt;iostream&amp;gt;

extern "C" {
  void my_long_calc(void);
  void fortran_message(int* value, char* msg1, size_t* len1, char* msg2, size_t* len2);
}

void fortran_message(int* value, char* msg1, size_t* len1, char* msg2, size_t* len2)
{
  std::cout &amp;lt;&amp;lt; "value: " &amp;lt;&amp;lt; *value &amp;lt;&amp;lt; std::endl;
  std::cout &amp;lt;&amp;lt; "msg1: " &amp;lt;&amp;lt; msg1 &amp;lt;&amp;lt; std::endl;
  std::cout &amp;lt;&amp;lt; "len1: " &amp;lt;&amp;lt; *len1 &amp;lt;&amp;lt; std::endl;
  std::cout &amp;lt;&amp;lt; "msg2: " &amp;lt;&amp;lt; msg2 &amp;lt;&amp;lt; std::endl;
  std::cout &amp;lt;&amp;lt; "len2: " &amp;lt;&amp;lt; *len2 &amp;lt;&amp;lt; std::endl;
}

int main(void)
{
    my_long_calc();

    return 0;
}&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;My console:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="console.jpg"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/10526iBEAF8BCD926D14E5/image-size/large?v=v2&amp;amp;px=999&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="console.jpg" alt="console.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If is possible, I would like to send &lt;STRONG&gt;only the Fortran string&lt;/STRONG&gt; &lt;STRONG&gt;(without the length parameter).&lt;/STRONG&gt;....this string maybe will varying the size in run-time...&lt;BR /&gt;You can write in pure C function...no problems...&lt;BR /&gt;&lt;BR /&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 19:33:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144676#M138168</guid>
      <dc:creator>Maia__Nycholas</dc:creator>
      <dc:date>2019-08-14T19:33:00Z</dc:date>
    </item>
    <item>
      <title>The thing to remember about</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144677#M138169</link>
      <description>&lt;P&gt;The thing to remember about passing strings is that a Fortran character string (any length) is interoperable with an array of C characters. You didn't want to declare msg1 and msg2 as arrays of characters. Use instead:&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;character(kind=C_CHAR, len=5) :: msg1
character(kind=C_CHAR, len=5) :: msg2&lt;/PRE&gt;

&lt;P&gt;With that change your program works (using Intel Fortran and Microsoft C++). I can't comment on other combinations or tools.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 22:41:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144677#M138169</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2019-08-14T22:41:58Z</dc:date>
    </item>
    <item>
      <title>@Steve, now I would like to</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144678#M138170</link>
      <description>&lt;P&gt;@Steve, now I would like to know how to do&amp;nbsp; the string conversion in the opposite direction: From C char array to Fortran String:&lt;BR /&gt;Please, look the this input argument called 'json_path'...this is a C char array that is passed to this Fortran subroutine using Fortran 2003 binding.&lt;/P&gt;&lt;P&gt;The value of this argument should be&amp;nbsp;a full path of a JSON file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;subroutine fortran_subroutine(json_path) bind(C)
&amp;nbsp; &amp;nbsp; use, intrinsic :: ISO_C_BINDING
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; use json_module
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; implicit none
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; character(kind=C_CHAR), intent(in) :: json_path(*)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; type(json_file) :: json
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ! initialize the class
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; call json%initialize()
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ! read the file: '../files/my_json.json'
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; call json%load_file(filename = json_path)

end subroutine fortran_subroutine&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;How can I convert C char array to a Fortran string?&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2019 19:34:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144678#M138170</guid>
      <dc:creator>Maia__Nycholas</dc:creator>
      <dc:date>2019-08-19T19:34:00Z</dc:date>
    </item>
    <item>
      <title>You've identified a big hole</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144679#M138171</link>
      <description>&lt;P&gt;You've identified a big hole in Fortran's C interop features. I have proposed new intrinsics for the next revision to address this. (See &lt;A href="https://j3-fortran.org/doc/year/18/18-258r2.txt"&gt;here&lt;/A&gt; and &lt;A href="https://j3-fortran.org/doc/year/19/19-197r3.txt"&gt;here&lt;/A&gt;. The first link includes an implementation you can use today.)&lt;/P&gt;&lt;P&gt;Basically what you need to do is declare a CHARACTER(:), POINTER, determine the string length by searching for the NUL, then pointer assign using that length using C_LOC(string-array)&amp;nbsp;and C_F_POINTER. This gets you a Fortran-friendly character value with length.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2019 23:16:22 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144679#M138171</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2019-08-19T23:16:22Z</dc:date>
    </item>
    <item>
      <title>@Steve, thank you for your</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144680#M138172</link>
      <description>&lt;P&gt;@Steve, &lt;STRONG&gt;thank you &lt;/STRONG&gt;for your Fortran example...but I'm a C/C++ guy and&lt;STRONG&gt; I'm newer in Fortran world.&lt;/STRONG&gt;&lt;BR /&gt;I tried to understand this example, but it is very complex&lt;STRONG&gt; to my current Fortran knowledge.&lt;/STRONG&gt;&lt;BR /&gt;But I &lt;STRONG&gt;can't wait&lt;/STRONG&gt; to implement this feature in my job...could you please help me a little bit more?&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;My C code is like:&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE class="brush:cpp; class-name:dark;"&gt;int main(void)
{
    char json_path[100] = "../files/json/my_example.json";
    char log_path[100] = "../files/log/my_log.json";
    
    fortran_subroutine(json_path, log_path);

    return 0;
}&lt;/PRE&gt;

&lt;P&gt;I copied your Fortran subroutine, but I don't&lt;STRONG&gt; understand how to use it?&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;My Fortran code:&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:fortran; class-name:dark;"&gt;subroutine C_F_STRPOINTER (STRARRAY, FSTRPTR, MAXLEN)
    use, intrinsic :: ISO_C_BINDING
    implicit none
    character, dimension(*), target, intent(in) :: STRARRAY
    character(:), pointer, intent(out) :: FSTRPTR
    integer, intent(in), optional :: MAXLEN

    integer :: curlen

    curlen = 0
    
    do
        curlen = curlen +1
        if (PRESENT(MAXLEN)) THEN
            if (curlen &amp;gt; MAXLEN) exit
        end if
        if (STRARRAY(CURLEN) == CHAR(0)) exit
    end do

    call doassign(C_LOC(STRARRAY), FSTRPTR, curlen-1)

    contains

    subroutine doassign(CSTRPTR, FSTRPTR, STRLEN)
        type(C_PTR), intent(in) :: CSTRPTR
        character(:), pointer, intent(out) :: FSTRPTR
        integer, intent(in) :: STRLEN

        character(STRLEN), pointer :: p

        call C_F_POINTER(CSTRPTR, p)
        FSTRPTR =&amp;gt; p
        return
    end subroutine doassign
end subroutine C_F_STRPOINTER
    
    
subroutine fortran_subroutine(json_path, log_path) bind(C)
    use, intrinsic :: ISO_C_BINDING
                
        use json_module
        
        implicit none
        character(kind=C_CHAR), intent(in) :: json_path(*)
        character(kind=C_CHAR), intent(in) :: log_path(*)
        
        type(json_file) :: my_data, my_log
        
        ! initialize the class
        call my_data%initialize()
        call my_log%initialize()
        
        ! read the file: SHOUD BE filename = json_path
        call my_data%load_file(filename = 'inout.json')

        ! read the file: SHOUD BE filename = log_path
        call my_log%load_file(filename = 'inout.json')

end subroutine fortran_subroutine
&lt;/PRE&gt;

&lt;P&gt;How can I pass the 2 C char arrays ('json_path' and 'log_path') to my Fortran subroutine in a way that I can use these&amp;nbsp;Fortran commands?&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:; class-name:dark;"&gt;call my_data%load_file(filename = json_path)
call my_log%load_file(filename = log_path)&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Could you help me?&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2019 12:51:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144680#M138172</guid>
      <dc:creator>Maia__Nycholas</dc:creator>
      <dc:date>2019-08-20T12:51:14Z</dc:date>
    </item>
    <item>
      <title>extern "C" {</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144681#M138173</link>
      <description>&lt;PRE class="brush:cpp; class-name:dark;"&gt;extern "C" {
	void fortran_subroutine(char* jpath, char* lpath);
}

int main(void)
{
	char json_path[100] = "../files/json/my_example.json";
	char log_path[100] = "../files/log/my_log.json";

	fortran_subroutine(json_path, log_path);

	return 0;
}&lt;/PRE&gt;

&lt;PRE class="brush:fortran; class-name:dark;"&gt;module str_routines
    contains
    subroutine C_F_STRPOINTER (STRARRAY, FSTRPTR, MAXLEN)
    use, intrinsic :: ISO_C_BINDING
    implicit none
    character, dimension(*), target, intent(in) :: STRARRAY
    character(:), pointer, intent(out) :: FSTRPTR
    integer, intent(in), optional :: MAXLEN

    integer :: curlen

    curlen = 0
    
    do
        curlen = curlen +1
        if (PRESENT(MAXLEN)) THEN
            if (curlen &amp;gt; MAXLEN) exit
        end if
        if (STRARRAY(CURLEN) == CHAR(0)) exit
    end do

    call doassign(C_LOC(STRARRAY), FSTRPTR, curlen-1)

    contains

    subroutine doassign(CSTRPTR, FSTRPTR, STRLEN)
        type(C_PTR), intent(in) :: CSTRPTR
        character(:), pointer, intent(out) :: FSTRPTR
        integer, intent(in) :: STRLEN

        character(STRLEN), pointer :: p

        call C_F_POINTER(CSTRPTR, p)
        FSTRPTR =&amp;gt; p
        return
    end subroutine doassign
    end subroutine C_F_STRPOINTER
    end module str_routines
    
    
subroutine fortran_subroutine(json_path, log_path) bind(C)
    use, intrinsic :: ISO_C_BINDING
                
!        use json_module
         use str_routines
        
        implicit none
        character(kind=C_CHAR), target, intent(in) :: json_path(*)
        character(kind=C_CHAR), target, intent(in) :: log_path(*)
        
        character(kind=C_CHAR, len=:), pointer :: jpath, lpath
        
        call C_F_STRPOINTER (json_path, jpath, 80)
        call C_F_STRPOINTER (log_path, lpath, 80)
        
        print "('""',A,'""')", jpath, lpath
        
!        type(json_file) :: my_data, my_log
        
        ! initialize the class
!        call my_data%initialize()
!        call my_log%initialize()
        
        ! read the file: SHOUD BE filename = json_path
!        call my_data%load_file(filename = 'inout.json')

        ! read the file: SHOUD BE filename = log_path
!        call my_log%load_file(filename = 'inout.json')

end subroutine fortran_subroutine&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2019 13:30:01 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144681#M138173</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2019-08-20T13:30:01Z</dc:date>
    </item>
    <item>
      <title>Thank you so much @Steve for</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144682#M138174</link>
      <description>&lt;P&gt;Thank you so much @Steve for your patience and quick response! &lt;STRONG&gt;You are the best!&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2019 13:47:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144682#M138174</guid>
      <dc:creator>Maia__Nycholas</dc:creator>
      <dc:date>2019-08-20T13:47:47Z</dc:date>
    </item>
    <item>
      <title>Steve,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144683#M138175</link>
      <description>&lt;P&gt;Steve,&lt;/P&gt;&lt;P&gt;Can you comment on the subtleties?&lt;/P&gt;&lt;P&gt;The subroutine fortran_subroutine is declared as taking two assumed-length character arguments. Which to my understanding actually has four arguments (two are the hidden lengths of the&amp;nbsp;(*) two arguments.&lt;/P&gt;&lt;P&gt;It is clear that your use in this subroutine does NOT use the assumed length arguments other than to pass the references to another subroutine that uses only the address of the arguments and not the missing assumed length.&lt;/P&gt;&lt;P&gt;The temptation for some junior programmer to see this example, and assume the malformed assumed-length arguments are correct is too high. I would recommend that due to the requirement to scan for NULL character termination is required, that the scan be performed on the C/C++ side via a help function and that the call pass the length along with the address as a C_PTR.&lt;/P&gt;&lt;P&gt;As it stands, a helper function is required on one side or the other. My preference is to do this on the C/C++ side.&lt;/P&gt;&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2019 15:56:24 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144683#M138175</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2019-08-20T15:56:24Z</dc:date>
    </item>
    <item>
      <title>Jim,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144684#M138176</link>
      <description>&lt;P&gt;Jim,&lt;/P&gt;&lt;P&gt;The arguments to fortran_subroutine are assumed-size arrays of CHARACTER*1, &lt;STRONG&gt;not &lt;/STRONG&gt;assumed-length! There are no hidden arguments because of the BIND(C).&amp;nbsp;The (Fortran) standard says that there is a 1-1 correspondence between the dummy arguments declared in Fortran and the "parameters" in C.&lt;/P&gt;&lt;P&gt;Traditionally, one (sometimes) passed string lengths from C to Fortran, but there was no standard about how Fortran would accept these. In the Windows/UNIX world Fortran compilers typically used hidden arguments, but there was inconsistency as to where in the argument list they were placed (at the end or after each address). Some other platforms (I am familiar with VMS) use different mechanisms, such as descriptors.&lt;/P&gt;&lt;P&gt;With the advent of Fortran 2003, if you chose to use the interoperability features you were required to do away with hidden arguments. Some chose to have declared dummy arguments to accept the lengths, others (such as in this case) have to assume the C scheme of a trailing null.&lt;/P&gt;&lt;P&gt;As of Fortran 2018 (and the TS29113 Technical Specification published in 2012, supported by Intel as of version 16), a third possibility opened up: a CHARACTER(*) (assumed-length) dummy argument is interoperable with a "C descriptor", but it's unlikely this would be the first choice of most C programmers. It does, however, lay a trap for the unwary. Prior to this, you could not have a CHARACTER(*) argument to a BIND(C) routine, now you can. Programmers not aware of the semantics of this might wonder why their programs fail when they used the familiar CHARACTER(*).&lt;/P&gt;&lt;P&gt;There are many ways to solve string length problems - a lot depends on which side of the call you want to put the effort into.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2019 16:57:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144684#M138176</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2019-08-20T16:57:00Z</dc:date>
    </item>
    <item>
      <title>Quote:jimdempseyatthecove</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144685#M138177</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;jimdempseyatthecove (Blackbelt) wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;..&lt;/P&gt;&lt;P&gt;The temptation for some junior programmer to see this example, and assume the malformed assumed-length arguments are correct is too high. I would recommend that due to the requirement to scan for NULL character termination is required, that the scan be performed on the C/C++ side via a help function and that the call pass the length along with the address as a C_PTR.&lt;/P&gt;&lt;P&gt;As it stands, a helper function is required on one side or the other. My preference is to do this on the C/C++ side. ..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jim,&lt;/P&gt;&lt;P&gt;You make excellent points here and I hope programmers reading this thread would pay close attention.&lt;/P&gt;&lt;P&gt;There is a reason why in Quote #3 upthread I wrote this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;FortranFan wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;..&amp;nbsp;While passing "string" data from/to Fortran with other languages such as C++,&amp;nbsp; passing the string length&amp;nbsp;as shown can simplify the&amp;nbsp;interoperation considerably.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;which is to both ease the exchange of "string" data across the 2 programming language environments but also to facilitate good coding practices (GCP) by those programmers out there, especially the one you refer to, who read this thread.&amp;nbsp; Because as you allude to, there are several issues of concern which can easily be overlooked by unsuspecting readers or be thought of as the way to do things e.g., the "magic number" of 80 in lines 53 and 54 in the second code snippet in Quote #14.&lt;/P&gt;&lt;P&gt;As you also say correctly with "&amp;nbsp;My preference is to do this on the C/C++ side" given&amp;nbsp;"the requirement to scan for NULL character termination", it is not only trivial but can also lead to very concise and clear code on both sides as can be seen in an alternate example below:&lt;/P&gt;
&lt;PRE class="brush:cpp; class-name:dark;"&gt;#include &amp;lt;cstring&amp;gt;
#include &amp;lt;iostream&amp;gt;

extern "C" {

   // Function prototype
   void Fortran_subroutine( const char *, size_t, const char *, size_t );

}

int main(void)
{

   std::cout &amp;lt;&amp;lt; "Option 1 using C-style char array" &amp;lt;&amp;lt; std::endl;
   {
      char json_path[] = "../files/json/my_example.json";
      char log_path[] = "../files/log/my_log.json";

      Fortran_subroutine(json_path, strlen(json_path), log_path, strlen(log_path) );
   }

   std::cout &amp;lt;&amp;lt; "Option 2 using std::string C++ class" &amp;lt;&amp;lt; std::endl;
   {
      std::string JsonFilePath = "../files/json/my_example.json";
      std::string LogFilePath = "../files/log/my_log.json";

      Fortran_subroutine(JsonFilePath.c_str(), JsonFilePath.length(), LogFilePath.c_str(), LogFilePath.length() );
   }

   return 0;

}
&lt;/PRE&gt;

&lt;PRE class="brush:fortran; class-name:dark;"&gt;module m

   use, intrinsic :: iso_c_binding, only : c_char, c_size_t, c_f_pointer, c_loc

   implicit none

contains

   subroutine Fsub(json_path, len_json, log_path, len_log) bind(C, name="Fortran_subroutine")

      ! Argument list
      character(kind=c_char,len=1), target, intent(in) :: json_path(*)
      integer(c_size_t), intent(in), value             :: len_json
      character(kind=c_char,len=1), target, intent(in) :: log_path(*)
      integer(c_size_t), intent(in), value             :: len_log

      ! Local variables
      character(kind=c_char,len=len_json), pointer :: path_json
      character(kind=c_char,len=len_log), pointer :: path_log

      call c_f_pointer( cptr=c_loc(json_path), fptr=path_json )
      print *, "path_json = ", path_json
      print *, "length: ", len(path_json), "; expected is ", len_json

      call c_f_pointer( cptr=c_loc(log_path), fptr=path_log )
      print *, "path_log = ", path_log
      print *, "length: ", len(path_log), "; expected is ", len_log

      path_json =&amp;gt; null()
      path_log =&amp;gt; null()

      return

   end subroutine

end module
&lt;/PRE&gt;

&lt;P&gt;Upon execution of the above, the expected output as seen using both Intel Fortran+Microsoft C++ and GCC/gfortran toolsets is:&lt;/P&gt;

&lt;PRE class="brush:plain; class-name:dark;"&gt;Option 1 using C-style char array
 path_json = ../files/json/my_example.json
 length:           29 ; expected is                    29
 path_log = ../files/log/my_log.json
 length:           24 ; expected is                    24
Option 2 using std::string C++- class
 path_json = ../files/json/my_example.json
 length:           29 ; expected is                    29
 path_log = ../files/log/my_log.json
 length:           24 ; expected is                    24
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2019 20:41:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144685#M138177</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2019-08-21T20:41:20Z</dc:date>
    </item>
    <item>
      <title>This example gives lots of C+</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144686#M138178</link>
      <description>&lt;P&gt;This example gives lots of C++ compile warnings, but works, with old tools - MSVC 14 (i.e. VS 8) and IVF 11.0.075.&amp;nbsp; I'm impressed!&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 04:50:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144686#M138178</guid>
      <dc:creator>gib</dc:creator>
      <dc:date>2019-08-22T04:50:12Z</dc:date>
    </item>
    <item>
      <title>Quote:gib wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144687#M138179</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;gib wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This example gives lots of C++ compile warnings, but works, with old tools - MSVC 14 (i.e. VS 8) and IVF 11.0.075.&amp;nbsp; I'm impressed!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Which example, which Quote #??&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 13:10:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144687#M138179</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2019-08-22T13:10:02Z</dc:date>
    </item>
  </channel>
</rss>

