Files
2025-10-25 03:02:53 +03:00

56 lines
2.2 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[basic.stc.static]
# 6 Basics [[basic]](./#basic)
## 6.8 Memory and objects [[basic.memobj]](basic.memobj#basic.stc.static)
### 6.8.6 Storage duration [[basic.stc]](basic.stc#static)
#### 6.8.6.2 Static storage duration [basic.stc.static]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L4285)
All variables which
- [(1.1)](#1.1)
do not have thread storage duration and
- [(1.2)](#1.2)
belong to a namespace scope ([[basic.scope.namespace]](basic.scope.namespace "6.4.6Namespace scope")) or
are first declared with
the static or extern keywords ([[dcl.stc]](dcl.stc "9.2.2Storage class specifiers"))
have [*static storage duration*](#def:storage_duration,static "6.8.6.2Static storage duration[basic.stc.static]")[.](#1.sentence-1)
The storage for these entities lasts for the duration of the
program ([[basic.start.static]](basic.start.static "6.10.3.2Static initialization"), [[basic.start.term]](basic.start.term "6.10.3.4Termination"))[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L4299)
If a variable with static storage duration has initialization or a
destructor with side effects, it shall not be eliminated even if it
appears to be unused, except that a class object or its copy/move may be
eliminated as specified in [[class.copy.elision]](class.copy.elision "11.9.6Copy/move elision")[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L4305)
[*Note [1](#note-1)*:
The keyword static can be used to declare
a block variable ([[basic.scope.block]](basic.scope.block "6.4.3Block scope")) with static storage duration;[[stmt.dcl]](stmt.dcl "8.10Declaration statement") and [[basic.start.term]](basic.start.term "6.10.3.4Termination") describe the
initialization and destruction of such variables[.](#3.sentence-1)
The keyword static applied to
a class data member in a class definition
gives the data member static storage duration ([[class.static.data]](class.static.data "11.4.9.3Static data members"))[.](#3.sentence-2)
— *end note*]