Fuad Tabba | c588ecf | 2021-02-04 13:59:53 +0000 | [diff] [blame^] | 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-2015 Free Software Foundation, Inc. |
| 4 | |
| 5 | Permission is granted to copy, distribute and/or modify this document |
| 6 | under the terms of the GNU Free Documentation License, Version 1.3 or |
| 7 | any later version published by the Free Software Foundation; with the |
| 8 | Invariant Sections being "Funding Free Software", the Front-Cover |
| 9 | Texts being (a) (see below), and with the Back-Cover Texts being (b) |
| 10 | (see below). A copy of the license is included in the section entitled |
| 11 | "GNU Free Documentation License". |
| 12 | |
| 13 | (a) The FSF's Front-Cover Text is: |
| 14 | |
| 15 | A GNU Manual |
| 16 | |
| 17 | (b) The FSF's Back-Cover Text is: |
| 18 | |
| 19 | You have freedom to copy and modify this GNU Manual, like GNU |
| 20 | software. Copies published by the Free Software Foundation raise |
| 21 | funds for GNU development. --> |
| 22 | <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ --> |
| 23 | <head> |
| 24 | <title>The GNU Fortran Compiler: Argument list functions</title> |
| 25 | |
| 26 | <meta name="description" content="The GNU Fortran Compiler: Argument list functions"> |
| 27 | <meta name="keywords" content="The GNU Fortran Compiler: Argument list functions"> |
| 28 | <meta name="resource-type" content="document"> |
| 29 | <meta name="distribution" content="global"> |
| 30 | <meta name="Generator" content="makeinfo"> |
| 31 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 32 | <link href="index.html#Top" rel="start" title="Top"> |
| 33 | <link href="Option-Index.html#Option-Index" rel="index" title="Option Index"> |
| 34 | <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> |
| 35 | <link href="Extensions-implemented-in-GNU-Fortran.html#Extensions-implemented-in-GNU-Fortran" rel="up" title="Extensions implemented in GNU Fortran"> |
| 36 | <link href="Read_002fWrite-after-EOF-marker.html#Read_002fWrite-after-EOF-marker" rel="next" title="Read/Write after EOF marker"> |
| 37 | <link href="OpenACC.html#OpenACC" rel="prev" title="OpenACC"> |
| 38 | <style type="text/css"> |
| 39 | <!-- |
| 40 | a.summary-letter {text-decoration: none} |
| 41 | blockquote.smallquotation {font-size: smaller} |
| 42 | div.display {margin-left: 3.2em} |
| 43 | div.example {margin-left: 3.2em} |
| 44 | div.indentedblock {margin-left: 3.2em} |
| 45 | div.lisp {margin-left: 3.2em} |
| 46 | div.smalldisplay {margin-left: 3.2em} |
| 47 | div.smallexample {margin-left: 3.2em} |
| 48 | div.smallindentedblock {margin-left: 3.2em; font-size: smaller} |
| 49 | div.smalllisp {margin-left: 3.2em} |
| 50 | kbd {font-style:oblique} |
| 51 | pre.display {font-family: inherit} |
| 52 | pre.format {font-family: inherit} |
| 53 | pre.menu-comment {font-family: serif} |
| 54 | pre.menu-preformatted {font-family: serif} |
| 55 | pre.smalldisplay {font-family: inherit; font-size: smaller} |
| 56 | pre.smallexample {font-size: smaller} |
| 57 | pre.smallformat {font-family: inherit; font-size: smaller} |
| 58 | pre.smalllisp {font-size: smaller} |
| 59 | span.nocodebreak {white-space:nowrap} |
| 60 | span.nolinebreak {white-space:nowrap} |
| 61 | span.roman {font-family:serif; font-weight:normal} |
| 62 | span.sansserif {font-family:sans-serif; font-weight:normal} |
| 63 | ul.no-bullet {list-style: none} |
| 64 | --> |
| 65 | </style> |
| 66 | |
| 67 | |
| 68 | </head> |
| 69 | |
| 70 | <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> |
| 71 | <a name="Argument-list-functions"></a> |
| 72 | <div class="header"> |
| 73 | <p> |
| 74 | Next: <a href="Read_002fWrite-after-EOF-marker.html#Read_002fWrite-after-EOF-marker" accesskey="n" rel="next">Read/Write after EOF marker</a>, Previous: <a href="OpenACC.html#OpenACC" accesskey="p" rel="prev">OpenACC</a>, Up: <a href="Extensions-implemented-in-GNU-Fortran.html#Extensions-implemented-in-GNU-Fortran" accesskey="u" rel="up">Extensions implemented in GNU Fortran</a> [<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> |
| 75 | </div> |
| 76 | <hr> |
| 77 | <a name="Argument-list-functions-_0025VAL_002c-_0025REF-and-_0025LOC"></a> |
| 78 | <h4 class="subsection">6.1.18 Argument list functions <code>%VAL</code>, <code>%REF</code> and <code>%LOC</code></h4> |
| 79 | <a name="index-argument-list-functions"></a> |
| 80 | <a name="index-_0025VAL"></a> |
| 81 | <a name="index-_0025REF"></a> |
| 82 | <a name="index-_0025LOC"></a> |
| 83 | |
| 84 | <p>GNU Fortran supports argument list functions <code>%VAL</code>, <code>%REF</code> |
| 85 | and <code>%LOC</code> statements, for backward compatibility with g77. |
| 86 | It is recommended that these should be used only for code that is |
| 87 | accessing facilities outside of GNU Fortran, such as operating system |
| 88 | or windowing facilities. It is best to constrain such uses to isolated |
| 89 | portions of a program–portions that deal specifically and exclusively |
| 90 | with low-level, system-dependent facilities. Such portions might well |
| 91 | provide a portable interface for use by the program as a whole, but are |
| 92 | themselves not portable, and should be thoroughly tested each time they |
| 93 | are rebuilt using a new compiler or version of a compiler. |
| 94 | </p> |
| 95 | <p><code>%VAL</code> passes a scalar argument by value, <code>%REF</code> passes it by |
| 96 | reference and <code>%LOC</code> passes its memory location. Since gfortran |
| 97 | already passes scalar arguments by reference, <code>%REF</code> is in effect |
| 98 | a do-nothing. <code>%LOC</code> has the same effect as a Fortran pointer. |
| 99 | </p> |
| 100 | <p>An example of passing an argument by value to a C subroutine foo.: |
| 101 | </p><div class="smallexample"> |
| 102 | <pre class="smallexample">C |
| 103 | C prototype void foo_ (float x); |
| 104 | C |
| 105 | external foo |
| 106 | real*4 x |
| 107 | x = 3.14159 |
| 108 | call foo (%VAL (x)) |
| 109 | end |
| 110 | </pre></div> |
| 111 | |
| 112 | <p>For details refer to the g77 manual |
| 113 | <a href="https://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/index.html#Top">https://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/index.html#Top</a>. |
| 114 | </p> |
| 115 | <p>Also, <code>c_by_val.f</code> and its partner <code>c_by_val.c</code> of the |
| 116 | GNU Fortran testsuite are worth a look. |
| 117 | </p> |
| 118 | |
| 119 | |
| 120 | |
| 121 | </body> |
| 122 | </html> |