Пространства имён
Варианты
Действия

Storage duration specifiers

Материал из cppreference.com

 
 
Язык С++
Общие темы
Управление программой
Операторы условного выполнения
Операторы повторения
Операторы перехода
Функции
объявление функции
объявление лямбда-функции
шаблон функции
спецификатор inline
спецификаторы исключений (устарело)
спецификатор noexcept (C++11)
Исключения
Пространства имён
объявление пространства имён
псевдонимы пространства имён
Типы
спецификатор decltype (C++11)
Спецификаторы
cv-спецификаторы
спецификаторы продолжительности хранения
спецификатор constexpr (C++11)
спецификатор auto (C++11)
спецификатор alignas (C++11)
Инициализация
Литералы
Выражения
Утилиты
Типы
typedef-объявление
объявление псевдонима типа (C++11)
атрибуты (C++11)
Приведения типов
неявные преобразования
const_cast-преобразование
static_cast-преобразование
dynamic_cast-преобразование
reinterpret_cast-преобразование
C-подобное и функциональное приведение типов
Выделение памяти
Классы
Особые свойства классовых функций
Специальные функции-члены
Шаблоны
шаблон класса
шаблон функции
специализация шаблона
упакованные параметры (C++11)
Разное
Ассемблерные вставки
 
  • auto -' автоматической длительности хранения. (устарело)
    Original:
    auto - automatic storage duration. (устарело)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • register -' автоматической длительности хранения. Также подсказки компилятору разместить переменную в регистре процессора. (устарело)
    Original:
    register - automatic storage duration. Also hints to the compiler to place the variable in the processor's register. (устарело)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • static -' статической памяти продолжительность и' внутренней связи
    Original:
    static - static storage duration and internal linkage
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • extern - статической памяти' продолжительности и внешних связей
    Original:
    extern - static storage duration and external linkage
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • thread_local - потока длительности хранения. (начиная с C++11)
    Original:
    thread_local - thread storage duration. (начиная с C++11)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

Содержание

[править] Объяснение

[править] Хранение продолжительности

Все переменные в программе есть одна из следующих длительности хранения
Original:
All variables in a program have one of the following storage durations:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • ' 'Автоматические длительности хранения. Переменных выделяется в начале ограждающих блоков кода и освобождаются от конца. Все не глобальные переменные этом длительность хранения, за исключением тех заявил static, extern или thread_local.
    Original:
    automatic storage duration. The variable is allocated at the beginning of the enclosing code block and deallocated on end. All non-global variables have this storage duration, except those declared static, extern or thread_local.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • ' 'Статической длительности хранения. Переменную выделяется при запуске программы и освобождаются, когда программа заканчивается. Только один экземпляр переменной не существует. Все глобальные переменные имеют эту длительность хранения, а также тех, кто объявлен с static или extern.
    Original:
    static storage duration. The variable is allocated when the program begins and deallocated when the program ends. Only one instance of the variable exists. All global variables have this storage duration, plus those declared with static or extern.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • ' 'Поток длительность хранения (начиная с C++11). Переменную выделяется, когда поток начинает и освобождается, когда поток завершается. Каждый поток имеет свой собственный экземпляр переменной. Только переменные, объявленные thread_local эту длительности хранения. thread_local может быть объявлен только для глобальных переменных, а также тех, кто объявлен с static или extern.
    Original:
    thread storage duration (начиная с C++11). The variable is allocated when the thread begins and deallocated when the thread ends. Each thread has its own instance of the variable. Only variables declared thread_local have this storage duration. thread_local can only be declared for global variables, plus those declared with static or extern.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

[править] Связь

Связь относится к способности переменной или функции должен быть передан в других областях. Если переменная или функция с тем же идентификатором объявлена ​​в нескольких областях, но не могут быть отнесены к не все из них, а затем несколько экземпляров переменной создаются. Следующие связи признаются:
Original:
Linkage refers to the ability of a variable or function to be referred to in other scopes. If a variable or function with the same identifier is declared in several scopes, but cannot be referred to from all of them, then several instances of the variable are generated. The following linkages are recognized:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • ' 'Никакой связи. Переменная может быть передан только из сферы это дюйма Все переменные с автоматической, резьба и динамические длительности хранения есть эта связь.
    Original:
    no linkage. The variable can be referred to only from the scope it is in. All variables with automatic, thread and dynamic storage durations have this linkage.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • ' 'Внутренней связи. Переменная может быть отнесено к из всех областей в текущей единице перевода. Все переменные со статическим срок хранения которых являются либо объявлены static, или const, но не extern, имеют эту связь.
    Original:
    internal linkage. The variable can be referred to from all scopes in the current translation unit. All variables with static storage duration which are either declared static, or const but not extern, have this linkage.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • ' 'Внешних связей. Переменная может быть отнесено к из областей в других единицах трансляции. Все переменные со статическим срок хранения у такой связи, за исключением тех заявил static, или const, но не extern.
    Original:
    external linkage. The variable can be referred to from the scopes in the other translation units. All variables with static storage duration have this linkage, except those declared static, or const but not extern.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

[править] Ключевые слова

auto, register, static, extern, thread_local

[править] Пример