Further-Interoperability-of-Fortran-with-C.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1999-2017 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>The GNU Fortran Compiler: Further Interoperability of Fortran with C</title>
  20. <meta name="description" content="The GNU Fortran Compiler: Further Interoperability of Fortran with C">
  21. <meta name="keywords" content="The GNU Fortran Compiler: Further Interoperability of Fortran with C">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Interoperability-with-C.html#Interoperability-with-C" rel="up" title="Interoperability with C">
  30. <link href="GNU-Fortran-Compiler-Directives.html#GNU-Fortran-Compiler-Directives" rel="next" title="GNU Fortran Compiler Directives">
  31. <link href="Working-with-Pointers.html#Working-with-Pointers" rel="prev" title="Working with Pointers">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style:oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Further-Interoperability-of-Fortran-with-C"></a>
  63. <div class="header">
  64. <p>
  65. Previous: <a href="Working-with-Pointers.html#Working-with-Pointers" accesskey="p" rel="prev">Working with Pointers</a>, Up: <a href="Interoperability-with-C.html#Interoperability-with-C" accesskey="u" rel="up">Interoperability with C</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  66. </div>
  67. <hr>
  68. <a name="Further-Interoperability-of-Fortran-with-C-1"></a>
  69. <h4 class="subsection">7.1.6 Further Interoperability of Fortran with C</h4>
  70. <p>The Technical Specification ISO/IEC TS 29113:2012 on further
  71. interoperability of Fortran with C extends the interoperability support
  72. of Fortran 2003 and Fortran 2008. Besides removing some restrictions
  73. and constraints, it adds assumed-type (<code>TYPE(*)</code>) and assumed-rank
  74. (<code>dimension</code>) variables and allows for interoperability of
  75. assumed-shape, assumed-rank and deferred-shape arrays, including
  76. allocatables and pointers.
  77. </p>
  78. <p>Note: Currently, GNU Fortran does not support the array descriptor
  79. (dope vector) as specified in the Technical Specification, but uses
  80. an array descriptor with different fields. The Chasm Language
  81. Interoperability Tools, <a href="http://chasm-interop.sourceforge.net/">http://chasm-interop.sourceforge.net/</a>,
  82. provide an interface to GNU Fortran&rsquo;s array descriptor.
  83. </p>
  84. <p>The Technical Specification adds the following new features, which
  85. are supported by GNU Fortran:
  86. </p>
  87. <ul>
  88. <li> The <code>ASYNCHRONOUS</code> attribute has been clarified and
  89. extended to allow its use with asynchronous communication in
  90. user-provided libraries such as in implementations of the
  91. Message Passing Interface specification.
  92. </li><li> Many constraints have been relaxed, in particular for
  93. the <code>C_LOC</code> and <code>C_F_POINTER</code> intrinsics.
  94. </li><li> The <code>OPTIONAL</code> attribute is now allowed for dummy
  95. arguments; an absent argument matches a <code>NULL</code> pointer.
  96. </li><li> Assumed types (<code>TYPE(*)</code>) have been added, which may
  97. only be used for dummy arguments. They are unlimited polymorphic
  98. but contrary to <code>CLASS(*)</code> they do not contain any type
  99. information, similar to C&rsquo;s <code>void *</code> pointers. Expressions
  100. of any type and kind can be passed; thus, it can be used as
  101. replacement for <code>TYPE(C_PTR)</code>, avoiding the use of
  102. <code>C_LOC</code> in the caller.
  103. <p>Note, however, that <code>TYPE(*)</code> only accepts scalar arguments,
  104. unless the <code>DIMENSION</code> is explicitly specified. As
  105. <code>DIMENSION(*)</code> only supports array (including array elements) but
  106. no scalars, it is not a full replacement for <code>C_LOC</code>. On the
  107. other hand, assumed-type assumed-rank dummy arguments
  108. (<code>TYPE(*), DIMENSION(..)</code>) allow for both scalars and arrays, but
  109. require special code on the callee side to handle the array descriptor.
  110. </p>
  111. </li><li> Assumed-rank arrays (<code>DIMENSION(..)</code>) as dummy argument
  112. allow that scalars and arrays of any rank can be passed as actual
  113. argument. As the Technical Specification does not provide for direct
  114. means to operate with them, they have to be used either from the C side
  115. or be converted using <code>C_LOC</code> and <code>C_F_POINTER</code> to scalars
  116. or arrays of a specific rank. The rank can be determined using the
  117. <code>RANK</code> intrinisic.
  118. </li></ul>
  119. <p>Currently unimplemented:
  120. </p>
  121. <ul>
  122. <li> GNU Fortran always uses an array descriptor, which does not
  123. match the one of the Technical Specification. The
  124. <code>ISO_Fortran_binding.h</code> header file and the C functions it
  125. specifies are not available.
  126. </li><li> Using assumed-shape, assumed-rank and deferred-shape arrays in
  127. <code>BIND(C)</code> procedures is not fully supported. In particular,
  128. C interoperable strings of other length than one are not supported
  129. as this requires the new array descriptor.
  130. </li></ul>
  131. <hr>
  132. <div class="header">
  133. <p>
  134. Previous: <a href="Working-with-Pointers.html#Working-with-Pointers" accesskey="p" rel="prev">Working with Pointers</a>, Up: <a href="Interoperability-with-C.html#Interoperability-with-C" accesskey="u" rel="up">Interoperability with C</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  135. </div>
  136. </body>
  137. </html>