Skip to content

Commit e56aa6a

Browse files
author
Colin Robertson
committed
Overhaul of C++ keywords
1 parent 28fd4ed commit e56aa6a

31 files changed

Lines changed: 732 additions & 468 deletions

docs/build/ieee-floating-point-representation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ms.assetid: 537833e8-fe05-49fc-8169-55fd0314b195
66
---
77
# IEEE Floating-Point Representation
88

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.
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.
1010

1111
The values are stored as follows:
1212

docs/build/reference/zp-struct-member-alignment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ You can also use [pack](../../preprocessor/pack.md) to control structure packing
3636

3737
- [align](../../cpp/align-cpp.md)
3838

39-
- [__alignof Operator](../../cpp/alignof-operator.md)
39+
- [alignof Operator](../../cpp/alignof-operator.md)
4040

4141
- [__unaligned](../../cpp/unaligned.md)
4242

docs/c-language/c-sized-integer-types.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
---
22
title: "C Sized Integer Types"
3-
ms.date: "11/04/2016"
3+
ms.date: 07/22/2020
44
helpviewer_keywords: ["sized integer types"]
55
ms.assetid: 0d6199b4-d0ab-4e8c-a769-785f5afb92eb
66
---
77
# C Sized Integer Types
88

99
**Microsoft Specific**
1010

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:
1212

13-
```
14-
__int8 nSmall; // Declares 8-bit integer
13+
```C
14+
__int8 nSmall; // Declares 8-bit integer
1515
__int16 nMedium; // Declares 16-bit integer
1616
__int32 nLarge; // Declares 32-bit integer
1717
__int64 nHuge; // Declares 64-bit integer
1818
```
1919

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`**.
2121

2222
**END Microsoft Specific**
2323

docs/c-language/integer-types.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
title: "Integer Types"
3-
ms.date: "11/04/2016"
3+
ms.date: 07/22/2020
44
helpviewer_keywords: ["integer data type, integer types in C++", "integer constants", "integer types", "integers, types"]
55
ms.assetid: c8926a5e-0e98-4e37-9b05-ce97961379bd
66
---
77
# Integer Types
88

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:
1010

11-
```
11+
```C
1212
/* Long decimal constants */
1313
10L
1414
79L
@@ -26,17 +26,17 @@ Every integer constant is given a type based on its value and the way it is expr
2626
778866LU
2727
```
2828

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.
3030

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.
3232

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.
3434

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.
3636

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.
3838

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`**.
4040

4141
## See also
4242

docs/cpp/align-cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Writing applications that use the latest processor instructions introduces some
2323

2424
\# 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.
2525

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).
2727

2828
You can use `__declspec(align(#))` when you define a **struct**, **union**, or **class**, or when you declare a variable.
2929

docs/cpp/alignment-cpp-declarations.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.assetid: a986d510-ccb8-41f8-b905-433df9183485
88

99
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.
1010

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.
1212

1313
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.
1414

@@ -92,11 +92,11 @@ adr offset element
9292

9393
## alignof and alignas
9494

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.
9696

9797
## Example
9898

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).
100100

101101
```cpp
102102
// alignas_alignof.cpp

docs/cpp/alignof-operator.md

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,58 @@
11
---
2-
title: "__alignof Operator"
2+
title: "alignof Operator"
33
ms.date: "12/17/2018"
44
f1_keywords: ["__alignof_cpp", "alignof_cpp", "__alignof", "_alignof"]
55
helpviewer_keywords: ["alignas [C++]", "alignment of structures", "__alignof keyword [C++]", "alignof [C++]", "types [C++], alignment requirements"]
66
ms.assetid: acb1eed7-6398-40bd-b0c5-684ceb64afbc
77
---
8-
# __alignof Operator
8+
# alignof Operator
99

10-
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`**.
1511

1612
## Syntax
1713

1814
```cpp
19-
__alignof( type )
15+
alignof( type )
2016
```
2117

2218
## Remarks
2319

2420
For example:
2521

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 |
3530

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:
3732

3833
```cpp
3934
typedef struct { int a; double b; } S;
40-
// __alignof(S) == 8
35+
// alignof(S) == 8
4136
```
4237
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.
4439
4540
Similarly, for
4641
4742
```cpp
4843
typedef __declspec(align(32)) struct { int a; } S;
4944
```
5045

51-
`__alignof(S)` is equal to `32`.
46+
`alignof(S)` is equal to `32`.
5247

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.
5449

5550
```cpp
5651
typedef __declspec(align(32)) struct { int a; double b; } S;
5752
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));
5954
```
6055
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-
6356
For more information on modifying alignment, see:
6457
6558
- [pack](../preprocessor/pack.md)
@@ -76,7 +69,11 @@ For more information on differences in alignment in code for x86 and x64, see:
7669
7770
- [Conflicts with the x86 Compiler](../build/x64-software-conventions.md#conflicts-with-the-x86-compiler)
7871
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.
8077
8178
## See also
8279

0 commit comments

Comments
 (0)