summaryrefslogtreecommitdiff
path: root/devdocs/c/language%2Fstatic_storage_duration.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/language%2Fstatic_storage_duration.html
new repository
Diffstat (limited to 'devdocs/c/language%2Fstatic_storage_duration.html')
-rw-r--r--devdocs/c/language%2Fstatic_storage_duration.html32
1 files changed, 32 insertions, 0 deletions
diff --git a/devdocs/c/language%2Fstatic_storage_duration.html b/devdocs/c/language%2Fstatic_storage_duration.html
new file mode 100644
index 00000000..2ca1a227
--- /dev/null
+++ b/devdocs/c/language%2Fstatic_storage_duration.html
@@ -0,0 +1,32 @@
+ <h1 id="firstHeading" class="firstHeading">Static storage duration</h1> <p>An object whose identifier is declared without the storage-class specifier <code>_Thread_local</code>, and either with external or internal <a href="storage_duration#Linkage" title="c/language/storage duration">linkage</a> or with the storage-class specifier <code>static</code>, has static storage duration. Its lifetime is the entire execution of the program and its stored value is initialized only once, prior to program startup.</p>
+<h3 id="Notes"> Notes</h3> <p>Since its stored value is initialized only once, an object with static storage duration can profile the invocations of a function.</p>
+<p>The other use of the keyword <code>static</code> is <a href="file_scope" title="c/language/file scope">file scope</a>.</p>
+<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include &lt;stdio.h&gt;
+
+void f (void)
+{
+ static int count = 0; // static variable
+ int i = 0; // automatic variable
+ printf("%d %d\n", i++, count++);
+}
+
+int main(void)
+{
+ for (int ndx=0; ndx&lt;10; ++ndx)
+ f();
+}</pre></div> <p>Output:</p>
+<div class="text source-text"><pre data-language="c">0 0
+0 1
+0 2
+0 3
+0 4
+0 5
+0 6
+0 7
+0 8
+0 9</pre></div> </div> <div class="_attribution">
+ <p class="_attribution-p">
+ &copy; cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
+ <a href="https://en.cppreference.com/w/c/language/static_storage_duration" class="_attribution-link">https://en.cppreference.com/w/c/language/static_storage_duration</a>
+ </p>
+</div>