Skip to content

Commit dc416f3

Browse files
author
Colin Robertson
authored
Update C2603
Updates for recent compiler behavior, and formatting issues. Hat tip to @KorkyPlunger for the motivation.
1 parent fed18a9 commit dc416f3

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

docs/error-messages/compiler-errors-2/compiler-error-c2603.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,26 @@ translation.priority.ht:
3434
- "zh-cn"
3535
- "zh-tw"
3636
---
37-
# Compiler Error C2603
38-
'function' : Too many block scope static objects with constructor/destructors in function
37+
# Compiler Error C2603
3938

40-
There is a limit of 31 on the number of static objects you can have in an externally visible inline function.
39+
> '*function*' : Too many block scope static objects with constructor/destructors in function
4140
42-
The following code generates C2603:
41+
In versions of the Visual C++ compiler before Visual Studio 2015, or when the [/Zc:threadSafeInit-](../../build/reference/zc-threadsafeinit-thread-safe-local-static-initialization.md) compiler option is specified, there is a limit of 31 on the number of static objects you can have in an externally visible inline function.
4342

44-
```
43+
To resolve this issue, we recommend you adopt more recent version of the Visual C++ compiler toolset, or if possible, remove the /Zc:threadSafeInit- compiler option. If this is not possible, consider combining your static objects. If the objects are of the same type, consider use of a single static array of that type, and reference individual members as required.
44+
45+
## Example
46+
47+
The following code generates C2603 and shows one way to fix it:
48+
49+
```cpp
4550
// C2603.cpp
51+
// Compile by using: cl /W4 /c /Zc:threadSafeInit- C2603.cpp
4652
struct C { C() {} };
4753
extern inline void f1() {
48-
static C C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11,C12,C14,C15,C16;
49-
static C C17,C18,C19,C20,C21,C22,C23,C24,C25,C26,C27,C28,C29,C30,C31,C32;
50-
static C C33; // C2603 Comment this line out to avoid error
54+
static C C01, C02, C03, C04, C05, C06, C07, C08, C09, C10;
55+
static C C11, C12, C13, C14, C15, C16, C17, C18, C19, C20;
56+
static C C21, C22, C23, C24, C25, C26, C27, C28, C29, C30, C31;
57+
static C C32; // C2603 Comment this line out to avoid error
5158
}
52-
```
59+
```

0 commit comments

Comments
 (0)