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
Microsoft C++ (MSVC) is consistent with the IEEE numeric standards. The IEEE-754 standard describes floating-point formats, a way to represent real numbers in hardware. There are at least five internal formats for floating-point numbers that are representable in hardware targeted by the MSVC compiler, but the compiler only uses two of them. The *single-precision* (4-byte) and *double-precision* (8-byte) formats are used in MSVC. Single-precision is declared using the keyword **float**. Double-precision is declared using the keyword **double**. The IEEE standard also specifies *half-precision* (2-byte) and *quadruple-precision* (16-byte) formats, as well as an *double-extended-precision* (10-byte) format, which some C and C++ compilers implement as the **long double** data type. In the MSVC compiler, the **long double** data type is treated as a distinct type, but the storage type maps to **double**. There is, however, intrinsic and assembly language support for computations using the other formats, including the double-extended-precision (10-byte) format, where supported by hardware.
9
+
Microsoft C++ (MSVC) is consistent with the IEEE numeric standards. The IEEE-754 standard describes floating-point formats, a way to represent real numbers in hardware. There are at least five internal formats for floating-point numbers that are representable in hardware targeted by the MSVC compiler, but the compiler only uses two of them. The *single-precision* (4-byte) and *double-precision* (8-byte) formats are used in MSVC. Single-precision is declared using the keyword **`float`**. Double-precision is declared using the keyword **`double`**. The IEEE standard also specifies *half-precision* (2-byte) and *quadruple-precision* (16-byte) formats, as well as an *double-extended-precision* (10-byte) format, which some C and C++ compilers implement as the **`long double`** data type. In the MSVC compiler, the **`long double`** data type is treated as a distinct type, but the storage type maps to **`double`**. There is, however, intrinsic and assembly language support for computations using the other formats, including the double-extended-precision (10-byte) format, where supported by hardware.
Copy file name to clipboardExpand all lines: docs/c-language/c-sized-integer-types.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,23 +1,23 @@
1
1
---
2
2
title: "C Sized Integer Types"
3
-
ms.date: "11/04/2016"
3
+
ms.date: 07/22/2020
4
4
helpviewer_keywords: ["sized integer types"]
5
5
ms.assetid: 0d6199b4-d0ab-4e8c-a769-785f5afb92eb
6
6
---
7
7
# C Sized Integer Types
8
8
9
9
**Microsoft Specific**
10
10
11
-
Microsoft C features support for sized integer types. You can declare 8-, 16-, 32-, or 64-bit integer variables by using the __int*n* type specifier, where *n* is the size, in bits, of the integer variable. The value of *n* can be 8, 16, 32, or 64. The following example declares one variable of each of the four types of sized integers:
11
+
Microsoft C features support for sized integer types. You can declare 8-, 16-, 32-, or 64-bit integer variables by using the `__intN` type specifier, where *`N`* is the size, in bits, of the integer variable. The value of *n* can be 8, 16, 32, or 64. The following example declares one variable of each of the four types of sized integers:
12
12
13
-
```
14
-
__int8 nSmall; // Declares 8-bit integer
13
+
```C
14
+
__int8 nSmall; // Declares 8-bit integer
15
15
__int16 nMedium; // Declares 16-bit integer
16
16
__int32 nLarge; // Declares 32-bit integer
17
17
__int64 nHuge; // Declares 64-bit integer
18
18
```
19
19
20
-
The first three types of sized integers are synonyms for the ANSI types that have the same size, and are useful for writing portable code that behaves identically across multiple platforms. Note that the __int8 data type is synonymous with type char, \__int16 is synonymous with type short, and \__int32 is synonymous with type int. The \__int64 type has no equivalent ANSI counterpart.
20
+
The first three types of sized integers are synonyms for the ANSI types that have the same size. They're useful for writing portable code that behaves identically across multiple platforms. The **`__int8`** data type is synonymous with type **`char`**, **`__int16`** is synonymous with type **`short`**, **`__int32`** is synonymous with type **`int`**, and **`__int64`** is synonymous with type **`long long`**.
Copy file name to clipboardExpand all lines: docs/c-language/integer-types.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
@@ -1,14 +1,14 @@
1
1
---
2
2
title: "Integer Types"
3
-
ms.date: "11/04/2016"
3
+
ms.date: 07/22/2020
4
4
helpviewer_keywords: ["integer data type, integer types in C++", "integer constants", "integer types", "integers, types"]
5
5
ms.assetid: c8926a5e-0e98-4e37-9b05-ce97961379bd
6
6
---
7
7
# Integer Types
8
8
9
-
Every integer constant is given a type based on its value and the way it is expressed. You can force any integer constant to type **long** by appending the letter **l** or **L** to the end of the constant; you can force it to be type `unsigned` by appending **u** or **U** to the value. The lowercase letter **l** can be confused with the digit 1 and should be avoided. Some forms of **long** integer constants follow:
9
+
Every integer constant is given a type based on its value and the way it's expressed. You can force any integer constant to type **`long`** by appending the letter **`l`** or **`L`** to the end of the constant; you can force it to be type **`unsigned`** by appending **`u`** or **`U`** to the value. The lowercase letter **`l`** can be confused with the digit 1 and should be avoided. Some forms of **`long`** integer constants follow:
10
10
11
-
```
11
+
```C
12
12
/* Long decimal constants */
13
13
10L
14
14
79L
@@ -26,17 +26,17 @@ Every integer constant is given a type based on its value and the way it is expr
26
26
778866LU
27
27
```
28
28
29
-
The type you assign to a constant depends on the value the constant represents. A constant's value must be in the range of representable values for its type. A constant's type determines which conversions are performed when the constant is used in an expression or when the minus sign (**-**) is applied. This list summarizes the conversion rules for integer constants.
29
+
The type you assign to a constant depends on the value the constant represents. A constant's value must be in the range of representable values for its type. A constant's type determines which conversions are performed when the constant is used in an expression or when the minus sign (**`-`**) is applied. This list summarizes the conversion rules for integer constants.
30
30
31
-
- The type for a decimal constant without a suffix is either `int`, **long int**, or **unsigned long int**. The first of these three types in which the constant's value can be represented is the type assigned to the constant.
31
+
- The type for a decimal constant without a suffix is either **`int`**, **`long int`**, or **`unsigned long int`**. The first of these three types in which the constant's value can be represented is the type assigned to the constant.
32
32
33
-
- The type assigned to octal and hexadecimal constants without suffixes is `int`, `unsigned int`, **long int**, or **unsigned long int** depending on the size of the constant.
33
+
- The type assigned to octal and hexadecimal constants without suffixes is **`int`**, **`unsigned int`**, **`long int`**, or **`unsigned long int`** depending on the size of the constant.
34
34
35
-
- The type assigned to constants with a **u** or **U** suffix is **unsigned int** or **unsigned long int** depending on their size.
35
+
- The type assigned to constants with a **`u`** or **`U`** suffix is **`unsigned int`** or **`unsigned long int`** depending on their size.
36
36
37
-
- The type assigned to constants with an **l** or **L** suffix is **long int** or **unsigned long int** depending on their size.
37
+
- The type assigned to constants with an **`l`** or **`L`** suffix is **`long int`** or **`unsigned long int`** depending on their size.
38
38
39
-
- The type assigned to constants with a **u** or **U** and an **l** or **L** suffix is **unsigned long int**.
39
+
- The type assigned to constants with a **`u`** or **`U`** and an **`l`** or **`L`** suffix is **`unsigned long int`**.
Copy file name to clipboardExpand all lines: docs/cpp/align-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
@@ -23,7 +23,7 @@ Writing applications that use the latest processor instructions introduces some
23
23
24
24
\# is the alignment value. Valid entries are integer powers of two from 1 to 8192 (bytes), such as 2, 4, 8, 16, 32, or 64. `declarator` is the data that you are declaring as aligned.
25
25
26
-
For information about how to return a value of type `size_t` that is the alignment requirement of the type, see [__alignof](../cpp/alignof-operator.md). For information about how to declare unaligned pointers when targeting 64-bit processors, see [__unaligned](../cpp/unaligned.md).
26
+
For information about how to return a value of type `size_t` that is the alignment requirement of the type, see [alignof](../cpp/alignof-operator.md). For information about how to declare unaligned pointers when targeting 64-bit processors, see [__unaligned](../cpp/unaligned.md).
27
27
28
28
You can use `__declspec(align(#))` when you define a **struct**, **union**, or **class**, or when you declare a variable.
One of the low-level features of C++ is the ability to specify the precise alignment of objects in memory to take maximum advantage of a specific hardware architecture. By default, the compiler aligns class and struct members on their size value: `bool` and `char` on 1-byte boundaries, `short` on 2-byte boundaries, `int`, `long`, and `float` on 4-byte boundaries, and `long long`, `double`, and `long double` on 8-byte boundaries.
10
10
11
-
In most scenarios, you never have to be concerned with alignment because the default alignment is already optimal. In some cases, however, you can achieve significant performance improvements, or memory savings, by specifying a custom alignment for your data structures. Before Visual Studio 2015 you could use the Microsoft-specific keywords `__alignof` and `declspec(alignas)` to specify an alignment greater than the default. Starting in Visual Studio 2015 you should use the C++11 standard keywords **alignof** and **alignas** for maximum code portability. The new keywords behave in the same way under the hood as the Microsoft-specific extensions. The documentation for those extensions also applies to the new keywords. For more information, see [__alignof Operator](../cpp/alignof-operator.md) and [align](../cpp/align-cpp.md). The C++ standard doesn't specify packing behavior for alignment on boundaries smaller than the compiler default for the target platform, so you still need to use the Microsoft #pragma [pack](../preprocessor/pack.md) in that case.
11
+
In most scenarios, you never have to be concerned with alignment because the default alignment is already optimal. In some cases, however, you can achieve significant performance improvements, or memory savings, by specifying a custom alignment for your data structures. Before Visual Studio 2015 you could use the Microsoft-specific keywords **`__alignof`** and **`__declspec(align)`** to specify an alignment greater than the default. Starting in Visual Studio 2015 you should use the C++11 standard keywords **`alignof`** and **`alignas`** for maximum code portability. The new keywords behave in the same way under the hood as the Microsoft-specific extensions. The documentation for those extensions also applies to the new keywords. For more information, see [`alignof` Operator](../cpp/alignof-operator.md) and [align](../cpp/align-cpp.md). The C++ standard doesn't specify packing behavior for alignment on boundaries smaller than the compiler default for the target platform, so you still need to use the Microsoft #pragma [pack](../preprocessor/pack.md) in that case.
12
12
13
13
Use the [aligned_storage class](../standard-library/aligned-storage-class.md) for memory allocation of data structures with custom alignments. The [aligned_union class](../standard-library/aligned-union-class.md) is for specifying alignment for unions with non-trivial constructors or destructors.
14
14
@@ -92,11 +92,11 @@ adr offset element
92
92
93
93
## alignof and alignas
94
94
95
-
The **alignas** type specifier is a portable, C++ standard way to specify custom alignment of variables and user defined types. The **alignof** operator is likewise a standard, portable way to obtain the alignment of a specified type or variable.
95
+
The **`alignas`** type specifier is a portable, C++ standard way to specify custom alignment of variables and user defined types. The **`alignof`** operator is likewise a standard, portable way to obtain the alignment of a specified type or variable.
96
96
97
97
## Example
98
98
99
-
You can use **alignas** on a class, struct or union, or on individual members. When multiple **alignas** specifiers are encountered, the compiler will choose the strictest one, (the one with the largest value).
99
+
You can use **`alignas`** on a class, struct or union, or on individual members. When multiple **`alignas`** specifiers are encountered, the compiler will choose the strictest one, (the one with the largest value).
C++11 introduces the **alignof** operator that returns the alignment, in bytes, of the specified type. For maximum portability, you should use the alignof operator instead of the Microsoft-specific __alignof operator.
11
-
12
-
**Microsoft Specific**
13
-
14
-
Returns a value of type `size_t` that is the alignment requirement of the type.
10
+
The **`alignof`** operator returns the alignment in bytes of the specified type as a value of type **`size_t`**.
15
11
16
12
## Syntax
17
13
18
14
```cpp
19
-
__alignof( type )
15
+
alignof( type )
20
16
```
21
17
22
18
## Remarks
23
19
24
20
For example:
25
21
26
-
|Expression|Value|
27
-
|----------------|-----------|
28
-
|**__alignof( char )**|1|
29
-
|**__alignof( short )**|2|
30
-
|**__alignof( int )**|4|
31
-
|**__alignof( \__int64 )**|8|
32
-
|**__alignof( float )**|4|
33
-
|**__alignof( double )**|8|
34
-
|**__alignof( char\* )**|4|
22
+
| Expression | Value |
23
+
|--|--|
24
+
|**`alignof( char )`**| 1 |
25
+
|**`alignof( short )`**| 2 |
26
+
|**`alignof( int )`**| 4 |
27
+
|**`alignof( __int64 )`**| 8 |
28
+
|**`alignof( float )`**| 4 |
29
+
|**`alignof( double )`**| 8 |
35
30
36
-
The **__alignof** value is the same as the value for `sizeof` for basic types. Consider, however, this example:
31
+
The **`alignof`** value is the same as the value for `sizeof` for basic types. Consider, however, this example:
37
32
38
33
```cpp
39
34
typedefstruct { int a; double b; } S;
40
-
// __alignof(S) == 8
35
+
// alignof(S) == 8
41
36
```
42
37
43
-
In this case, the **__alignof** value is the alignment requirement of the largest element in the structure.
38
+
In this case, the **`alignof`** value is the alignment requirement of the largest element in the structure.
44
39
45
40
Similarly, for
46
41
47
42
```cpp
48
43
typedef __declspec(align(32)) struct { int a; } S;
49
44
```
50
45
51
-
`__alignof(S)` is equal to `32`.
46
+
`alignof(S)` is equal to `32`.
52
47
53
-
One use for **__alignof** would be as a parameter to one of your own memory-allocation routines. For example, given the following defined structure `S`, you could call a memory-allocation routine named `aligned_malloc` to allocate memory on a particular alignment boundary.
48
+
One use for **`alignof`** would be as a parameter to one of your own memory-allocation routines. For example, given the following defined structure `S`, you could call a memory-allocation routine named `aligned_malloc` to allocate memory on a particular alignment boundary.
54
49
55
50
```cpp
56
51
typedef__declspec(align(32)) struct { int a; double b; } S;
57
52
int n = 50; // array size
58
-
S* p = (S*)aligned_malloc(n * sizeof(S), __alignof(S));
53
+
S* p = (S*)aligned_malloc(n * sizeof(S), alignof(S));
59
54
```
60
55
61
-
For compatibility with previous versions, **_alignof** is a synonym for **__alignof** unless compiler option [/Za \(Disable language extensions)](../build/reference/za-ze-disable-language-extensions.md) is specified.
62
-
63
56
For more information on modifying alignment, see:
64
57
65
58
- [pack](../preprocessor/pack.md)
@@ -76,7 +69,11 @@ For more information on differences in alignment in code for x86 and x64, see:
76
69
77
70
- [Conflicts with the x86 Compiler](../build/x64-software-conventions.md#conflicts-with-the-x86-compiler)
78
71
79
-
**END Microsoft Specific**
72
+
### Microsoft-specific
73
+
74
+
**`alignof`** and **`__alignof`** are synonyms in the Microsoft compiler. Before it became part of the standard in C++11, the Microsoft-specific **`__alignof`** operator provided this functionality. For maximum portability, you should use the **`alignof`** operator instead of the Microsoft-specific **`__alignof`** operator.
75
+
76
+
For compatibility with previous versions, **`_alignof`** is a synonym for **`__alignof`** unless compiler option [`/Za` \(Disable language extensions)](../build/reference/za-ze-disable-language-extensions.md) is specified.
0 commit comments