source: public/doc/gnu-c/Local-Variables.html@ 02598c2

Last change on this file since 02598c2 was 02598c2, checked in by Mikhail Kirillov <w96k@…>, on Oct 6, 2022 at 12:36:29 PM

Add gnu-c

  • Property mode set to 100644
File size: 5.5 KB
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<!-- Copyright (C) 2022 Richard Stallman and Free Software Foundation, Inc.
4
5(The work of Trevis Rothwell and Nelson Beebe has been assigned or
6licensed to the FSF.)
7
8Permission is granted to copy, distribute and/or modify this document
9under the terms of the GNU Free Documentation License, Version 1.3 or
10any later version published by the Free Software Foundation; with the
11Invariant Sections being "GNU General Public License," with the
12Front-Cover Texts being "A GNU Manual," and with the Back-Cover
13Texts as in (a) below. A copy of the license is included in the
14section entitled "GNU Free Documentation License."
15
16(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
17modify this GNU manual. Buying copies from the FSF supports it in
18developing GNU and promoting software freedom." -->
19<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
20<head>
21<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
22<title>Local Variables (GNU C Language Manual)</title>
23
24<meta name="description" content="Local Variables (GNU C Language Manual)">
25<meta name="keywords" content="Local Variables (GNU C Language Manual)">
26<meta name="resource-type" content="document">
27<meta name="distribution" content="global">
28<meta name="Generator" content="makeinfo">
29<link href="index.html" rel="start" title="Top">
30<link href="Symbol-Index.html" rel="index" title="Symbol Index">
31<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
32<link href="Variables.html" rel="up" title="Variables">
33<link href="File_002dScope-Variables.html" rel="next" title="File-Scope Variables">
34<link href="Auto-Type.html" rel="prev" title="Auto Type">
35<style type="text/css">
36<!--
37a.summary-letter {text-decoration: none}
38blockquote.indentedblock {margin-right: 0em}
39div.display {margin-left: 3.2em}
40div.example {margin-left: 3.2em}
41div.lisp {margin-left: 3.2em}
42kbd {font-style: oblique}
43pre.display {font-family: inherit}
44pre.format {font-family: inherit}
45pre.menu-comment {font-family: serif}
46pre.menu-preformatted {font-family: serif}
47span.nolinebreak {white-space: nowrap}
48span.roman {font-family: initial; font-weight: normal}
49span.sansserif {font-family: sans-serif; font-weight: normal}
50ul.no-bullet {list-style: none}
51-->
52</style>
53
54
55</head>
56
57<body lang="en">
58<span id="Local-Variables"></span><div class="header">
59<p>
60Next: <a href="File_002dScope-Variables.html" accesskey="n" rel="next">File-Scope Variables</a>, Previous: <a href="Auto-Type.html" accesskey="p" rel="prev">Auto Type</a>, Up: <a href="Variables.html" accesskey="u" rel="up">Variables</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
61</div>
62<hr>
63<span id="Local-Variables-1"></span><h3 class="section">20.5 Local Variables</h3>
64<span id="index-local-variables"></span>
65<span id="index-variables_002c-local"></span>
66
67<p>Declaring a variable inside a function definition (see <a href="Function-Definitions.html">Function Definitions</a>) makes the variable name <em>local</em> to the containing
68block&mdash;that is, the containing pair of braces. More precisely, the
69variable&rsquo;s name is visible starting just after where it appears in the
70declaration, and its visibility continues until the end of the block.
71</p>
72<p>Local variables in C are generally <em>automatic</em> variables: each
73variable&rsquo;s storage exists only from the declaration to the end of the
74block. Execution of the declaration allocates the storage, computes
75the initial value, and stores it in the variable. The end of the
76block deallocates the storage.<a id="DOCF6" href="#FOOT6"><sup>6</sup></a>
77</p>
78<p><strong>Warning:</strong> Two declarations for the same local variable
79in the same scope are an error.
80</p>
81<p><strong>Warning:</strong> Automatic variables are stored in the run-time stack.
82The total space for the program&rsquo;s stack may be limited; therefore,
83in using very large arrays, it may be necessary to allocate
84them in some other way to stop the program from crashing.
85</p>
86<p><strong>Warning:</strong> If the declaration of an automatic variable does not
87specify an initial value, the variable starts out containing garbage.
88In this example, the value printed could be anything at all:
89</p>
90<div class="example">
91<pre class="example">{
92 int i;
93
94 printf (&quot;Print junk %d\n&quot;, i);
95}
96</pre></div>
97
98<p>In a simple test program, that statement is likely to print 0, simply
99because every process starts with memory zeroed. But don&rsquo;t rely on it
100to be zero&mdash;that is erroneous.
101</p>
102<p><strong>Note:</strong> Make sure to store a value into each local variable (by
103assignment, or by initialization) before referring to its value.
104</p>
105<div class="footnote">
106<hr>
107<h4 class="footnotes-heading">Footnotes</h4>
108
109<h5><a id="FOOT6" href="#DOCF6">(6)</a></h3>
110<p>Due to compiler optimizations,
111allocation and deallocation don&rsquo;t necessarily really happen at
112those times.</p>
113</div>
114<hr>
115<div class="header">
116<p>
117Next: <a href="File_002dScope-Variables.html" accesskey="n" rel="next">File-Scope Variables</a>, Previous: <a href="Auto-Type.html" accesskey="p" rel="prev">Auto Type</a>, Up: <a href="Variables.html" accesskey="u" rel="up">Variables</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
118</div>
119
120
121
122</body>
123</html>
Note: See TracBrowser for help on using the repository browser.