You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/cpp/static-assert.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ ms.author: "mblome"
13
13
ms.workload: ["cplusplus"]
14
14
---
15
15
# static_assert
16
-
Tests a software assertion at compile time. If the specified constant expression is `false`, the compiler displays the specified message, if one is provided, and the compilation fails with error C2338; otherwise, the declaration has no effect.
16
+
Tests a software assertion at compile time. If the specified constant expression is FALSE, the compiler displays the specified message, if one is provided, and the compilation fails with error C2338; otherwise, the declaration has no effect.
|`constant-expression`|An integral constant expression that can be converted to a Boolean.<br /><br /> If the evaluated expression is zero (false), the `string-literal` parameter is displayed and the compilation fails with an error. If the expression is nonzero (true), the `static_assert` declaration has no effect.|
31
+
|`constant-expression`|An integral constant expression that can be converted to a Boolean.<br /><br /> If the evaluated expression is zero (false), the `string-literal` parameter is displayed and the compilation fails with an error. If the expression is nonzero (true), the **static_assert** declaration has no effect.|
32
32
|`string-literal`|An message that is displayed if the `constant-expression` parameter is zero. The message is a string of characters in the [base character set](../c-language/ascii-character-set.md) of the compiler; that is, not [multibyte or wide characters](../c-language/multibyte-and-wide-characters.md).|
33
33
34
34
## Remarks
35
-
The `constant-expression` parameter of a `static_assert` declaration represents a *software assertion*. A software assertion specifies a condition that you expect to be true at a particular point in your program. If the condition is true, the `static_assert` declaration has no effect. If the condition is false, the assertion fails, the compiler displays the message in `string-literal` parameter, and the compilation fails with an error. In Visual Studio 2017 and later, the string-literal parameter is optional.
35
+
The `constant-expression` parameter of a **static_assert** declaration represents a *software assertion*. A software assertion specifies a condition that you expect to be true at a particular point in your program. If the condition is true, the **static_assert** declaration has no effect. If the condition is false, the assertion fails, the compiler displays the message in `string-literal` parameter, and the compilation fails with an error. In Visual Studio 2017 and later, the string-literal parameter is optional.
36
36
37
-
The `static_assert` declaration tests a software assertion at compile time. In contrast, the [assert Macro, _assert, _wassert](../c-runtime-library/reference/assert-macro-assert-wassert.md) macro tests a software assertion at run time and incurs a run time cost in space or time. The `static_assert` declaration is especially useful for debugging templates because template arguments can be included in the `constant-expression` parameter.
37
+
The **static_assert** declaration tests a software assertion at compile time. In contrast, the [assert Macro, _assert, _wassert](../c-runtime-library/reference/assert-macro-assert-wassert.md) macro tests a software assertion at run time and incurs a run time cost in space or time. The **static_assert** declaration is especially useful for debugging templates because template arguments can be included in the `constant-expression` parameter.
38
38
39
-
The compiler examines the `static_assert` declaration for syntax errors when the declaration is encountered. The compiler evaluates the `constant-expression` parameter immediately if it does not depend on a template parameter. Otherwise, the compiler evaluates the `constant-expression` parameter when the template is instantiated. Consequently, the compiler might issue a diagnostic message once when the declaration is encountered, and again when the template is instantiated.
39
+
The compiler examines the **static_assert** declaration for syntax errors when the declaration is encountered. The compiler evaluates the `constant-expression` parameter immediately if it does not depend on a template parameter. Otherwise, the compiler evaluates the `constant-expression` parameter when the template is instantiated. Consequently, the compiler might issue a diagnostic message once when the declaration is encountered, and again when the template is instantiated.
40
40
41
-
You can use the `static_assert` keyword at namespace, class, or block scope. (The `static_assert` keyword is technically a declaration, even though it does not introduce new name into your program, because it can be used at namespace scope.)
41
+
You can use the **static_assert** keyword at namespace, class, or block scope. (The **static_assert** keyword is technically a declaration, even though it does not introduce new name into your program, because it can be used at namespace scope.)
42
42
43
43
## Description
44
-
In the following example, the `static_assert` declaration has namespace scope. Because the compiler knows the size of type `void *`, the expression is evaluated immediately.
44
+
In the following example, the **static_assert** declaration has namespace scope. Because the compiler knows the size of type `void *`, the expression is evaluated immediately.
45
45
46
46
## Example
47
47
@@ -50,7 +50,7 @@ static_assert(sizeof(void *) == 4, "64-bit code generation is not supported.");
50
50
```
51
51
52
52
## Description
53
-
In the following example, the `static_assert` declaration has class scope. The `static_assert` verifies that a template parameter is a *plain old data* (POD) type. The compiler examines the `static_assert` declaration when it is declared, but does not evaluate the `constant-expression` parameter until the `basic_string` class template is instantiated in `main()`.
53
+
In the following example, the **static_assert** declaration has class scope. The **static_assert** verifies that a template parameter is a *plain old data* (POD) type. The compiler examines the **static_assert** declaration when it is declared, but does not evaluate the `constant-expression` parameter until the `basic_string` class template is instantiated in `main()`.
54
54
55
55
## Example
56
56
@@ -78,7 +78,7 @@ int main()
78
78
```
79
79
80
80
## Description
81
-
In the following example, the `static_assert` declaration has block scope. The `static_assert` verifies that the size of the VMPage structure is equal to the virtual memory pagesize of the system.
81
+
In the following example, the **static_assert** declaration has block scope. The **static_assert** verifies that the size of the VMPage structure is equal to the virtual memory pagesize of the system.
In standard C++, no run-time type check is made to help ensure the safety of the conversion. In C++/CX, a compile time and runtime check are performed. For more information, see [Casting](casting.md).
26
26
27
-
The `static_cast` operator can be used for operations such as converting a pointer to a base class to a pointer to a derived class. Such conversions are not always safe.
27
+
The **static_cast** operator can be used for operations such as converting a pointer to a base class to a pointer to a derived class. Such conversions are not always safe.
28
28
29
-
In general you use `static_cast` when you want to convert numeric data types such as enums to ints or ints to floats, and you are certain of the data types involved in the conversion. `static_cast` conversions are not as safe as `dynamic_cast` conversions, because `static_cast` does no run-time type check, while `dynamic_cast` does. A `dynamic_cast` to an ambiguous pointer will fail, while a `static_cast` returns as if nothing were wrong; this can be dangerous. Although `dynamic_cast` conversions are safer, `dynamic_cast` only works on pointers or references, and the run-time type check is an overhead. For more information, see [dynamic_cast Operator](../cpp/dynamic-cast-operator.md).
29
+
In general you use **static_cast** when you want to convert numeric data types such as enums to ints or ints to floats, and you are certain of the data types involved in the conversion. **static_cast** conversions are not as safe as **dynamic_cast** conversions, because **static_cast** does no run-time type check, while **dynamic_cast** does. A **dynamic_cast** to an ambiguous pointer will fail, while a **static_cast** returns as if nothing were wrong; this can be dangerous. Although **dynamic_cast** conversions are safer, **dynamic_cast** only works on pointers or references, and the run-time type check is an overhead. For more information, see [dynamic_cast Operator](../cpp/dynamic-cast-operator.md).
30
30
31
31
In the example that follows, the line `D* pd2 = static_cast<D*>(pb);` is not safe because `D` can have fields and methods that are not in `B`. However, the line `B* pb2 = static_cast<B*>(pd);` is a safe conversion because `D` always contains all of `B`.
32
32
@@ -46,9 +46,9 @@ void f(B* pb, D* pd) {
46
46
}
47
47
```
48
48
49
-
In contrast to [dynamic_cast](../cpp/dynamic-cast-operator.md), no run-time check is made on the `static_cast` conversion of `pb`. The object pointed to by `pb` may not be an object of type `D`, in which case the use of `*pd2` could be disastrous. For instance, calling a function that is a member of the `D` class, but not the `B` class, could result in an access violation.
49
+
In contrast to [dynamic_cast](../cpp/dynamic-cast-operator.md), no run-time check is made on the **static_cast** conversion of `pb`. The object pointed to by `pb` may not be an object of type `D`, in which case the use of `*pd2` could be disastrous. For instance, calling a function that is a member of the `D` class, but not the `B` class, could result in an access violation.
50
50
51
-
The `dynamic_cast` and `static_cast` operators move a pointer throughout a class hierarchy. However, `static_cast` relies exclusively on the information provided in the cast statement and can therefore be unsafe. For example:
51
+
The **dynamic_cast** and **static_cast** operators move a pointer throughout a class hierarchy. However, **static_cast** relies exclusively on the information provided in the cast statement and can therefore be unsafe. For example:
52
52
53
53
```cpp
54
54
// static_cast_Operator_2.cpp
@@ -67,13 +67,13 @@ void f(B* pb) {
67
67
68
68
If `pb` really points to an object of type `D`, then `pd1` and `pd2` will get the same value. They will also get the same value if `pb == 0`.
69
69
70
-
If `pb` points to an object of type `B` and not to the complete `D` class, then `dynamic_cast` will know enough to return zero. However, `static_cast` relies on the programmer's assertion that `pb` points to an object of type `D` and simply returns a pointer to that supposed `D` object.
70
+
If `pb` points to an object of type `B` and not to the complete `D` class, then **dynamic_cast** will know enough to return zero. However, **static_cast** relies on the programmer's assertion that `pb` points to an object of type `D` and simply returns a pointer to that supposed `D` object.
71
71
72
-
Consequently, `static_cast` can do the inverse of implicit conversions, in which case the results are undefined. It is left to the programmer to verify that the results of a `static_cast` conversion are safe.
72
+
Consequently, **static_cast** can do the inverse of implicit conversions, in which case the results are undefined. It is left to the programmer to verify that the results of a **static_cast** conversion are safe.
73
73
74
-
This behavior also applies to types other than class types. For instance, `static_cast` can be used to convert from an int to a `char`. However, the resulting `char` may not have enough bits to hold the entire `int` value. Again, it is left to the programmer to verify that the results of a `static_cast` conversion are safe.
74
+
This behavior also applies to types other than class types. For instance, **static_cast** can be used to convert from an int to a **char**. However, the resulting **char** may not have enough bits to hold the entire **int** value. Again, it is left to the programmer to verify that the results of a **static_cast** conversion are safe.
75
75
76
-
The `static_cast` operator can also be used to perform any implicit conversion, including standard conversions and user-defined conversions. For example:
76
+
The **static_cast** operator can also be used to perform any implicit conversion, including standard conversions and user-defined conversions. For example:
77
77
78
78
```cpp
79
79
// static_cast_Operator_3.cpp
@@ -92,15 +92,15 @@ void f() {
92
92
}
93
93
```
94
94
95
-
The `static_cast` operator can explicitly convert an integral value to an enumeration type. If the value of the integral type does not fall within the range of enumeration values, the resulting enumeration value is undefined.
95
+
The **static_cast** operator can explicitly convert an integral value to an enumeration type. If the value of the integral type does not fall within the range of enumeration values, the resulting enumeration value is undefined.
96
96
97
-
The `static_cast` operator converts a null pointer value to the null pointer value of the destination type.
97
+
The **static_cast** operator converts a null pointer value to the null pointer value of the destination type.
98
98
99
-
Any expression can be explicitly converted to type void by the `static_cast` operator. The destination void type can optionally include the `const`, `volatile`, or `__unaligned` attribute.
99
+
Any expression can be explicitly converted to type void by the **static_cast** operator. The destination void type can optionally include the **const**, **volatile**, or **__unaligned** attribute.
100
100
101
-
The `static_cast` operator cannot cast away the `const`, `volatile`, or `__unaligned` attributes. See [const_cast Operator](../cpp/const-cast-operator.md) for information on removing these attributes.
101
+
The **static_cast** operator cannot cast away the **const**, **volatile**, or **__unaligned** attributes. See [const_cast Operator](../cpp/const-cast-operator.md) for information on removing these attributes.
102
102
103
-
Due to the danger of performing unchecked casts on top of a relocating garbage collector, the use of `static_cast` should only be in performance-critical code when you are certain it will work correctly. If you must use `static_cast` in release mode, substitute it with [safe_cast](../windows/safe-cast-cpp-component-extensions.md) in your debug builds to ensure success.
103
+
Due to the danger of performing unchecked casts on top of a relocating garbage collector, the use of **static_cast** should only be in performance-critical code when you are certain it will work correctly. If you must use **static_cast** in release mode, substitute it with [safe_cast](../windows/safe-cast-cpp-component-extensions.md) in your debug builds to ensure success.
Copy file name to clipboardExpand all lines: docs/cpp/static-members-cpp.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,7 +65,7 @@ long nBytes = Console.bytecount;
65
65
66
66
Static data members are subject to class-member access rules, so private access to static data members is allowed only for class-member functions and friends. These rules are described in [Member-Access Control](../cpp/member-access-control-cpp.md). The exception is that static data members must be defined in file scope regardless of their access restrictions. If the data member is to be explicitly initialized, an initializer must be provided with the definition.
67
67
68
-
The type of a static member is not qualified by its class name. Therefore, the type of `BufferedOutput::bytecount` is `long`.
68
+
The type of a static member is not qualified by its class name. Therefore, the type of `BufferedOutput::bytecount` is **long**.
69
69
70
70
## See Also
71
71
[Classes and Structs](../cpp/classes-and-structs-cpp.md)
Copy file name to clipboardExpand all lines: docs/cpp/stdcall.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ ms.workload: ["cplusplus"]
15
15
# __stdcall
16
16
**Microsoft Specific**
17
17
18
-
The `__stdcall` calling convention is used to call Win32 API functions. The callee cleans the stack, so the compiler makes **vararg** functions `__cdecl`. Functions that use this calling convention require a function prototype.
18
+
The **__stdcall** calling convention is used to call Win32 API functions. The callee cleans the stack, so the compiler makes **vararg** functions **__cdecl**. Functions that use this calling convention require a function prototype.
|Name-decoration convention|An underscore (_) is prefixed to the name. The name is followed by the at sign (@) followed by the number of bytes (in decimal) in the argument list. Therefore, the function declared as `int func( int a, double b )` is decorated as follows: `_func@12`|
36
36
|Case-translation convention|None|
37
37
38
-
The [/Gz](../build/reference/gd-gr-gv-gz-calling-convention.md) compiler option specifies `__stdcall` for all functions not explicitly declared with a different calling convention.
38
+
The [/Gz](../build/reference/gd-gr-gv-gz-calling-convention.md) compiler option specifies **__stdcall** for all functions not explicitly declared with a different calling convention.
39
39
40
-
Functions declared using the `__stdcall` modifier return values the same way as functions declared using [__cdecl](../cpp/cdecl.md).
40
+
Functions declared using the **__stdcall** modifier return values the same way as functions declared using [__cdecl](../cpp/cdecl.md).
41
41
42
-
On ARM and x64 processors, `__stdcall` is accepted and ignored by the compiler; on ARM and x64 architectures, by convention, arguments are passed in registers when possible, and subsequent arguments are passed on the stack.
42
+
On ARM and x64 processors, **__stdcall** is accepted and ignored by the compiler; on ARM and x64 architectures, by convention, arguments are passed in registers when possible, and subsequent arguments are passed on the stack.
43
43
44
44
For non-static class functions, if the function is defined out-of-line, the calling convention modifier does not have to be specified on the out-of-line definition. That is, for class non-static member methods, the calling convention specified during declaration is assumed at the point of definition. Given this class definition,
0 commit comments