blob: 3ff990354db7b649dc5990c2101289e7ec42cd9a [file] [log] [blame]
Fuad Tabbac588ecf2021-02-04 13:59:53 +00001<!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
5Permission is granted to copy, distribute and/or modify this document
6under the terms of the GNU Free Documentation License, Version 1.3 or
7any later version published by the Free Software Foundation; with the
8Invariant Sections being "Funding Free Software", the Front-Cover
9Texts 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
15A GNU Manual
16
17(b) The FSF's Back-Cover Text is:
18
19You 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<!--
40a.summary-letter {text-decoration: none}
41blockquote.smallquotation {font-size: smaller}
42div.display {margin-left: 3.2em}
43div.example {margin-left: 3.2em}
44div.indentedblock {margin-left: 3.2em}
45div.lisp {margin-left: 3.2em}
46div.smalldisplay {margin-left: 3.2em}
47div.smallexample {margin-left: 3.2em}
48div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
49div.smalllisp {margin-left: 3.2em}
50kbd {font-style:oblique}
51pre.display {font-family: inherit}
52pre.format {font-family: inherit}
53pre.menu-comment {font-family: serif}
54pre.menu-preformatted {font-family: serif}
55pre.smalldisplay {font-family: inherit; font-size: smaller}
56pre.smallexample {font-size: smaller}
57pre.smallformat {font-family: inherit; font-size: smaller}
58pre.smalllisp {font-size: smaller}
59span.nocodebreak {white-space:nowrap}
60span.nolinebreak {white-space:nowrap}
61span.roman {font-family:serif; font-weight:normal}
62span.sansserif {font-family:sans-serif; font-weight:normal}
63ul.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>
74Next: <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> &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>
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>
85and <code>%LOC</code> statements, for backward compatibility with g77.
86It is recommended that these should be used only for code that is
87accessing facilities outside of GNU Fortran, such as operating system
88or windowing facilities. It is best to constrain such uses to isolated
89portions of a program&ndash;portions that deal specifically and exclusively
90with low-level, system-dependent facilities. Such portions might well
91provide a portable interface for use by the program as a whole, but are
92themselves not portable, and should be thoroughly tested each time they
93are 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
96reference and <code>%LOC</code> passes its memory location. Since gfortran
97already passes scalar arguments by reference, <code>%REF</code> is in effect
98a 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
103C prototype void foo_ (float x);
104C
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
116GNU Fortran testsuite are worth a look.
117</p>
118
119
120
121</body>
122</html>