title: char array in C++ function doesn't correspond to Character array from Fortran calling program
body: <p>system:</p>
  <pre><code>Mac OSX Catalina
  GCC 10, GFORTRAN 10
  </code></pre>
  <p>I have this simple fortran program that calls a C++ void function.  The purpose is a toy example of passing a string from Fortran to C++ based on what I have been finding in examples, but something is not right</p>
  <pre><code># subf.f90
  program main
    use iso_c_binding
    character(len=256), target :: a_string
  
    interface
       subroutine print_string(fortran_string) Bind(C)
         use iso_c_binding
         TYPE(C_PTR) :: fortran_string
       end subroutine print_string
    end interface
  
    a_string = &quot;Hello world&quot; // C_NULL_CHAR
    print *, &quot;trying to print: &quot;, trim(a_string)
    print *, &quot;a string of length: &quot;, len(trim(a_string)) - 1
    call print_string(C_LOC(a_string))
  end program main
  </code></pre>
  <pre><code>// sub.cpp
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;cstring&gt;
  
  extern &quot;C&quot; {
    void print_string(const char * fortran_string);
  }
  
  void print_string(const char* fortran_string) {
    std::string forstring(fortran_string);
    std::cout &lt;&lt; &quot;sizeof fortran_string: &quot; &lt;&lt; sizeof fortran_string &lt;&lt; std::endl
              &lt;&lt; &quot;strlen of fortran_string: &quot; &lt;&lt; strlen(fortran_string) &lt;&lt; std::endl
              &lt;&lt; &quot;first char: &quot; &lt;&lt; fortran_string[0] &lt;&lt; std:: endl
              &lt;&lt; &quot;.length(): &quot; &lt;&lt; forstring.length() &lt;&lt; std::endl
              &lt;&lt; &quot;the actual string: `&quot; &lt;&lt; forstring &lt;&lt; &quot;`&quot; &lt;&lt; std::endl;
  }
  </code></pre>
  <p>I compile and run with <code>g++-10 sub.cpp -c &amp;&amp; gfortran subf.f90 sub.o -o sub -lstdc++ &amp;&amp; ./sub</code></p>
  <p>The first character always seems to be <code>p</code> and the size of the passed string is always the same but where is <code>p</code> coming from?, why is the string garbage? and why doesn't the size match what I sent over from fortran?</p>
  <p>Here is a sample output:</p>
  <pre><code>&gt; ./sub
   trying to print: Hello world
   a string of length:           11
  sizeof fortran_string: 8
  strlen of fortran_string: 6
  first char: p
  .length(): 6
  the actual string: `p$??`
  </code></pre>