GNU-Fortran-Compiler-Directives.html 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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: GNU Fortran Compiler Directives</title>
  20. <meta name="description" content="The GNU Fortran Compiler: GNU Fortran Compiler Directives">
  21. <meta name="keywords" content="The GNU Fortran Compiler: GNU Fortran Compiler Directives">
  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="Mixed_002dLanguage-Programming.html#Mixed_002dLanguage-Programming" rel="up" title="Mixed-Language Programming">
  30. <link href="Non_002dFortran-Main-Program.html#Non_002dFortran-Main-Program" rel="next" title="Non-Fortran Main Program">
  31. <link href="Further-Interoperability-of-Fortran-with-C.html#Further-Interoperability-of-Fortran-with-C" rel="prev" title="Further Interoperability of Fortran with C">
  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="GNU-Fortran-Compiler-Directives"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Non_002dFortran-Main-Program.html#Non_002dFortran-Main-Program" accesskey="n" rel="next">Non-Fortran Main Program</a>, Previous: <a href="Interoperability-with-C.html#Interoperability-with-C" accesskey="p" rel="prev">Interoperability with C</a>, Up: <a href="Mixed_002dLanguage-Programming.html#Mixed_002dLanguage-Programming" accesskey="u" rel="up">Mixed-Language Programming</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="GNU-Fortran-Compiler-Directives-1"></a>
  69. <h3 class="section">7.2 GNU Fortran Compiler Directives</h3>
  70. <p>The Fortran standard describes how a conforming program shall
  71. behave; however, the exact implementation is not standardized. In order
  72. to allow the user to choose specific implementation details, compiler
  73. directives can be used to set attributes of variables and procedures
  74. which are not part of the standard. Whether a given attribute is
  75. supported and its exact effects depend on both the operating system and
  76. on the processor; see
  77. <a href="http://gcc.gnu.org/onlinedocs/gcc/index.html#Top">C Extensions</a> in <cite>Using the GNU Compiler Collection (GCC)</cite>
  78. for details.
  79. </p>
  80. <p>For procedures and procedure pointers, the following attributes can
  81. be used to change the calling convention:
  82. </p>
  83. <ul>
  84. <li> <code>CDECL</code> &ndash; standard C calling convention
  85. </li><li> <code>STDCALL</code> &ndash; convention where the called procedure pops the stack
  86. </li><li> <code>FASTCALL</code> &ndash; part of the arguments are passed via registers
  87. instead using the stack
  88. </li></ul>
  89. <p>Besides changing the calling convention, the attributes also influence
  90. the decoration of the symbol name, e.g., by a leading underscore or by
  91. a trailing at-sign followed by the number of bytes on the stack. When
  92. assigning a procedure to a procedure pointer, both should use the same
  93. calling convention.
  94. </p>
  95. <p>On some systems, procedures and global variables (module variables and
  96. <code>COMMON</code> blocks) need special handling to be accessible when they
  97. are in a shared library. The following attributes are available:
  98. </p>
  99. <ul>
  100. <li> <code>DLLEXPORT</code> &ndash; provide a global pointer to a pointer in the DLL
  101. </li><li> <code>DLLIMPORT</code> &ndash; reference the function or variable using a
  102. global pointer
  103. </li></ul>
  104. <p>For dummy arguments, the <code>NO_ARG_CHECK</code> attribute can be used; in
  105. other compilers, it is also known as <code>IGNORE_TKR</code>. For dummy arguments
  106. with this attribute actual arguments of any type and kind (similar to
  107. <code>TYPE(*)</code>), scalars and arrays of any rank (no equivalent
  108. in Fortran standard) are accepted. As with <code>TYPE(*)</code>, the argument
  109. is unlimited polymorphic and no type information is available.
  110. Additionally, the argument may only be passed to dummy arguments
  111. with the <code>NO_ARG_CHECK</code> attribute and as argument to the
  112. <code>PRESENT</code> intrinsic function and to <code>C_LOC</code> of the
  113. <code>ISO_C_BINDING</code> module.
  114. </p>
  115. <p>Variables with <code>NO_ARG_CHECK</code> attribute shall be of assumed-type
  116. (<code>TYPE(*)</code>; recommended) or of type <code>INTEGER</code>, <code>LOGICAL</code>,
  117. <code>REAL</code> or <code>COMPLEX</code>. They shall not have the <code>ALLOCATE</code>,
  118. <code>CODIMENSION</code>, <code>INTENT(OUT)</code>, <code>POINTER</code> or <code>VALUE</code>
  119. attribute; furthermore, they shall be either scalar or of assumed-size
  120. (<code>dimension(*)</code>). As <code>TYPE(*)</code>, the <code>NO_ARG_CHECK</code> attribute
  121. requires an explicit interface.
  122. </p>
  123. <ul>
  124. <li> <code>NO_ARG_CHECK</code> &ndash; disable the type, kind and rank checking
  125. </li></ul>
  126. <p>The attributes are specified using the syntax
  127. </p>
  128. <p><code>!GCC$ ATTRIBUTES</code> <var>attribute-list</var> <code>::</code> <var>variable-list</var>
  129. </p>
  130. <p>where in free-form source code only whitespace is allowed before <code>!GCC$</code>
  131. and in fixed-form source code <code>!GCC$</code>, <code>cGCC$</code> or <code>*GCC$</code> shall
  132. start in the first column.
  133. </p>
  134. <p>For procedures, the compiler directives shall be placed into the body
  135. of the procedure; for variables and procedure pointers, they shall be in
  136. the same declaration part as the variable or procedure pointer.
  137. </p>
  138. <hr>
  139. <div class="header">
  140. <p>
  141. Next: <a href="Non_002dFortran-Main-Program.html#Non_002dFortran-Main-Program" accesskey="n" rel="next">Non-Fortran Main Program</a>, Previous: <a href="Interoperability-with-C.html#Interoperability-with-C" accesskey="p" rel="prev">Interoperability with C</a>, Up: <a href="Mixed_002dLanguage-Programming.html#Mixed_002dLanguage-Programming" accesskey="u" rel="up">Mixed-Language Programming</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>
  142. </div>
  143. </body>
  144. </html>