Skip to content

Commit 02ec2e7

Browse files
mikeblomeColin Robertson
authored andcommitted
fixed typo on storage class page (#269)
* corrections for thread_local per dev team * corrections to thread_local per tech review * formatting corrections per review
1 parent affe8c7 commit 02ec2e7

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

docs/cpp/storage-classes-cpp.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ translation.priority.ht:
3737
- "zh-tw"
3838
---
3939
# Storage classes (C++)
40-
A *storage class* in the context of C++ variable declarations is a type specifier that governs the lifetime, linkage, and memory location of objects and. A given object can have only one storage class. Variables defined within a block have automatic storage unless otherwise specified using the `extern`, `static`, or `thread_local` specifiers. Automatic objects and variables have no linkage; they are not visible to code outside the block.
40+
A *storage class* in the context of C++ variable declarations is a type specifier that governs the lifetime, linkage, and memory location of objects. A given object can have only one storage class. Variables defined within a block have automatic storage unless otherwise specified using the `extern`, `static`, or `thread_local` specifiers. Automatic objects and variables have no linkage; they are not visible to code outside the block.
4141

4242
**Notes**
4343

4444
1. The [mutable](../cpp/mutable-data-members-cpp.md) keyword may be considered a storage class specifier. However, it is only available in the member list of a class definition.
4545

4646
2. Starting with [!INCLUDE[cpp_dev10_long](../build/includes/cpp_dev10_long_md.md)], the `auto` keyword is no longer a C++ storage-class specifier, and the `register` keyword is deprecated.
47+
48+
## In this section:
4749

4850
- [static](#static)
4951

@@ -60,7 +62,7 @@ A *storage class* in the context of C++ variable declarations is a type specifie
6062

6163
2. When you declare a variable in a function, the `static` keyword specifies that the variable retains its state between calls to that function.
6264

63-
3. When you declare a data member in a class declaration, the `static` keyword specifies that one copy of the member is shared by all instances of the class. A static data member must be defined at file scope. An integral data member that you declare as `const``static` can have an initializer.
65+
3. When you declare a data member in a class declaration, the `static` keyword specifies that one copy of the member is shared by all instances of the class. A static data member must be defined at file scope. An integral data member that you declare as `const static` can have an initializer.
6466

6567
4. When you declare a member function in a class declaration, the `static` keyword specifies that the function is shared by all instances of the class. A static member function cannot access an instance member because the function does not have an implicit `this` pointer. To access an instance member, declare the function with a parameter that is an instance pointer or reference.
6668

@@ -199,29 +201,31 @@ int main() {
199201
A variable declared with the `thread_local` specifier is accessible only on the thread on which it is created. The variable is created when the thread is created, and destroyed when the thread is destroyed. Each thread has its own copy of the variable. On Windows, `thread_local` is functionally equivalent to the Microsoft-specific [__declspec( thread )](../cpp/thread.md) attribute.
200202

201203
```
202-
thread_local float f = 42.0; //global namespace
204+
thread_local float f = 42.0; // Global namespace. Not implicitly static.
203205
204206
struct C // cannot be applied to type definition
205207
{
206-
thread_local int i; //local
207-
thread_local static char buf[10]; // local and static
208+
thread_local int i; // Illegal. The member must be static.
209+
thread_local static char buf[10]; // OK
208210
};
209211
210212
void DoSomething()
211213
{
212-
thread_local C my_struct; // Apply thread_local to a variable
214+
// Apply thread_local to a local variable.
215+
// Implicitly “thread_local static C my_struct”.
216+
thread_local C my_struct;
213217
}
214218
```
215219

216220
1. The thread_local specifier may be combined with `static` or `extern`.
217221

218-
2. You can apply `thread_local` only to data declarations and definitions; **thread_local** cannot be used on function declarations or definitions.
222+
2. You can apply `thread_local` only to data declarations and definitions; `thread_local` cannot be used on function declarations or definitions.
219223

220-
3. The use of `thread_local` may interfere with [delay loading](../build/reference/linker-support-for-delay-loaded-dlls.md) of DLL imports**.**
224+
3. The use of `thread_local` may interfere with [delay loading](../build/reference/linker-support-for-delay-loaded-dlls.md) of DLL imports.
221225

222226
4. On XP systems, `thread_local` may not function correctly if a DLL uses `thread_local` data and it is loaded dynamically via LoadLibrary.
223227

224-
5. You can specify `thread_local` only on data items with static storage duration. This includes global data objects (both **static** and `extern`), local static objects, and static data members of classes. You cannot declare automatic data objects with **thread_local**.
228+
5. You can specify `thread_local` only on data items with static storage duration. This includes global data objects (both `static` and `extern`), local static objects, and static data members of classes. Any local variable declared `thread_local` will be implicitly static if no other storage class is provided; in other words, at block scope `thread_local` is equivalent to `thread_local static`.
225229

226230
6. You must specify `thread_local` for both the declaration and the definition of a thread local object, whether the declaration and definition occur in the same file or separate files.
227231

0 commit comments

Comments
 (0)