From 527f7437f87b73f77cc52cdba02ae9fdfc604349 Mon Sep 17 00:00:00 2001 From: Colin Robertson <3836425+corob-msft@users.noreply.github.com> Date: Thu, 3 Nov 2022 18:23:33 -0700 Subject: [PATCH 1/5] Bulk fix code block spacing --- docs/atl/reference/iperpropertybrowsingimpl-class.md | 3 +-- docs/build/open-folder-projects-cpp.md | 2 -- docs/build/reference/allowbind.md | 1 - docs/build/reference/allowisolation.md | 1 - docs/build/reference/appcontainer.md | 1 - docs/c-language/generic-selection.md | 1 - docs/code-quality/c26117.md | 2 -- docs/code-quality/c26138.md | 2 -- docs/code-quality/c26160.md | 2 -- docs/code-quality/c26165.md | 2 -- docs/code-quality/c26166.md | 1 - docs/code-quality/c26167.md | 2 -- docs/code-quality/c26800.md | 2 -- docs/code-quality/c26810.md | 1 - docs/code-quality/c26811.md | 1 - docs/code-quality/c26828.md | 2 -- docs/code-quality/c6029.md | 1 - docs/code-quality/c6053.md | 3 --- docs/code-quality/c6387.md | 2 -- docs/code-quality/understanding-sal.md | 4 ---- .../using-rule-sets-to-specify-the-cpp-rules-to-run.md | 1 - docs/cpp/arrays-cpp.md | 2 -- docs/cpp/cpp-type-system-modern-cpp.md | 1 - docs/cpp/functions-cpp.md | 1 - .../object-lifetime-and-resource-management-modern-cpp.md | 1 - docs/cpp/raw-pointers.md | 1 - docs/cpp/welcome-back-to-cpp-modern-cpp.md | 1 - docs/cppcx/back-inserter-function.md | 1 - docs/cppcx/operator-type-hat.md | 1 - docs/cppcx/platform-collections-mapview-class.md | 1 - docs/cppcx/platform-collections-vectoriterator-class.md | 3 --- docs/cppcx/platform-collections-vectorview-class.md | 5 ----- .../cppcx/platform-collections-vectorviewiterator-class.md | 7 ------- docs/cppcx/threading-and-marshaling-c-cx.md | 2 -- docs/cppcx/value-classes-and-structs-c-cx.md | 2 -- docs/cppcx/weak-references-and-breaking-cycles-c-cx.md | 1 - .../cppcx/windows-foundation-collections-namespace-c-cx.md | 1 - .../tool-errors/linker-tools-warning-lnk4217.md | 1 - docs/ide/lnt-logical-bitwise-mismatch.md | 1 - docs/mfc/reference/cmfcribbonpanel-class.md | 1 - .../dao-database-engine-initialization-and-termination.md | 2 -- docs/mfc/reference/event-sink-maps.md | 2 -- docs/mfc/tn028-context-sensitive-help-support.md | 2 -- docs/overview/cpp-conformance-improvements-2019.md | 1 - docs/parallel/openmp/2-directives.md | 2 -- docs/standard-library/algorithm-functions.md | 4 ++-- docs/standard-library/basic-ios-class.md | 1 - docs/standard-library/memory-functions.md | 1 - docs/standard-library/string-view-operators.md | 1 - 49 files changed, 3 insertions(+), 84 deletions(-) diff --git a/docs/atl/reference/iperpropertybrowsingimpl-class.md b/docs/atl/reference/iperpropertybrowsingimpl-class.md index f81692daec9..cc1e9a5a450 100644 --- a/docs/atl/reference/iperpropertybrowsingimpl-class.md +++ b/docs/atl/reference/iperpropertybrowsingimpl-class.md @@ -15,8 +15,7 @@ This class implements `IUnknown` and allows a client to access the information i ## Syntax -``` - +```cpp template class ATL_NO_VTABLE IPerPropertyBrowsingImpl : public IPerPropertyBrowsing diff --git a/docs/build/open-folder-projects-cpp.md b/docs/build/open-folder-projects-cpp.md index 7e49f70c104..5d20f89c607 100644 --- a/docs/build/open-folder-projects-cpp.md +++ b/docs/build/open-folder-projects-cpp.md @@ -147,7 +147,6 @@ This creates (or opens) the *tasks.vs.json* file in the .vs folder which Visual } ] } - ``` The JSON file is placed in the *.vs* subfolder. To see that folder, click on the **Show All Files** button at the top of **Solution Explorer**. You can run this task by right-clicking on the root node in **Solution Explorer** and choosing **build hello**. When the task completes you should see a new file, *hello.exe* in **Solution Explorer**. @@ -194,7 +193,6 @@ To customize your program's command line arguments and debugging instructions, r } ] } - ``` To start debugging, choose the executable in the debug dropdown, then click the green arrow: diff --git a/docs/build/reference/allowbind.md b/docs/build/reference/allowbind.md index c57e11a6154..b7404db1754 100644 --- a/docs/build/reference/allowbind.md +++ b/docs/build/reference/allowbind.md @@ -11,7 +11,6 @@ ms.assetid: eaadbb8c-4339-4281-9a75-3a1ce2352ff8 Specifies whether a DLL can be bound. ``` - /ALLOWBIND[:NO] ``` diff --git a/docs/build/reference/allowisolation.md b/docs/build/reference/allowisolation.md index 28ab8b60385..579f9900b30 100644 --- a/docs/build/reference/allowisolation.md +++ b/docs/build/reference/allowisolation.md @@ -13,7 +13,6 @@ Specifies behavior for manifest lookup. ## Syntax ``` - /ALLOWISOLATION[:NO] ``` diff --git a/docs/build/reference/appcontainer.md b/docs/build/reference/appcontainer.md index 3b0db522a6f..7cf45709d12 100644 --- a/docs/build/reference/appcontainer.md +++ b/docs/build/reference/appcontainer.md @@ -11,7 +11,6 @@ ms.assetid: 0ca4f1ec-c8de-4a37-b3e2-deda7af0bb88 Marks an executable that must run in an app container—for example, a Microsoft Store or Universal Windows app. ``` - /APPCONTAINER[:NO] ``` diff --git a/docs/c-language/generic-selection.md b/docs/c-language/generic-selection.md index f5c1edd6c38..2e9872209a6 100644 --- a/docs/c-language/generic-selection.md +++ b/docs/c-language/generic-selection.md @@ -67,7 +67,6 @@ int main() /* Output: Type name: double */ - ``` ## Requirements diff --git a/docs/code-quality/c26117.md b/docs/code-quality/c26117.md index 8636bf604cc..235b47f14f4 100644 --- a/docs/code-quality/c26117.md +++ b/docs/code-quality/c26117.md @@ -17,7 +17,6 @@ Enforcement of syntactically scoped lock *acquire* and lock *release* pairs in C The following example generates warning C26117 because the function `ReleaseUnheldLock` releases a lock that it doesn't necessarily hold—the state of `flag` is ambiguous—and there's no annotation that specifies that it should. ```cpp - typedef struct _DATA { CRITICAL_SECTION cs; @@ -37,7 +36,6 @@ void ReleaseUnheldLock(DATA* p) The following code fixes the problem by guaranteeing that the released lock is also acquired under the same conditions. ```cpp - typedef struct _DATA { CRITICAL_SECTION cs; diff --git a/docs/code-quality/c26138.md b/docs/code-quality/c26138.md index 3861e5de370..08c847a5b02 100644 --- a/docs/code-quality/c26138.md +++ b/docs/code-quality/c26138.md @@ -20,7 +20,6 @@ Code analysis name: `SUSPENDED_WITH_LOCK` The following code will generate C26138. ```cpp - #include #include #include @@ -49,7 +48,6 @@ generator mutex_acquiring_generator_report_once() { The following code will correct these warnings. ```cpp - #include #include #include diff --git a/docs/code-quality/c26160.md b/docs/code-quality/c26160.md index c643d0b0750..2d8df17126b 100644 --- a/docs/code-quality/c26160.md +++ b/docs/code-quality/c26160.md @@ -17,7 +17,6 @@ Warning C26160 resembles warning [C26110](../code-quality/c26110.md) except that The following code generates warning C26160. ```cpp - struct Account { _Guarded_by_(cs) int balance; @@ -49,7 +48,6 @@ struct Account The following code shows a solution to the previous example. ```cpp - struct Account { _Guarded_by_(cs) int balance; diff --git a/docs/code-quality/c26165.md b/docs/code-quality/c26165.md index bf1ffcc2afb..973b4745d96 100644 --- a/docs/code-quality/c26165.md +++ b/docs/code-quality/c26165.md @@ -17,7 +17,6 @@ Warning C26165 resembles warning [C26115](../code-quality/c26115.md) except that The following code generates warning C26165. ```cpp - _Create_lock_level_(LockLevelOne); _Create_lock_level_(LockLevelTwo); @@ -45,7 +44,6 @@ void testLockLevelledStruct(LockLevelledStruct* s) // Warning C26165 To correct this warning, change the previous example to the following. ```cpp - _Create_lock_level_(LockLevelOne); _Create_lock_level_(LockLevelTwo); diff --git a/docs/code-quality/c26166.md b/docs/code-quality/c26166.md index 937d5670766..04809e0a941 100644 --- a/docs/code-quality/c26166.md +++ b/docs/code-quality/c26166.md @@ -17,7 +17,6 @@ Warning C26166 resembles warning [C26116](../code-quality/c26116.md) except that The following code shows code that will generate warning C26166. ```cpp - typedef struct _DATA { CRITICAL_SECTION cs; } DATA; diff --git a/docs/code-quality/c26167.md b/docs/code-quality/c26167.md index 4468ddadbcb..8e7eea235ba 100644 --- a/docs/code-quality/c26167.md +++ b/docs/code-quality/c26167.md @@ -17,7 +17,6 @@ Warning C26167 resembles warning [C26117](../code-quality/c26117.md) except that The following code will generate C26167 and C26110. ```cpp - typedef struct _DATA { CRITICAL_SECTION cs; } DATA; @@ -34,7 +33,6 @@ void ReleaseUnheldLock(DATA* p) { // Warning C26167 The following code will correct these warnings. ```cpp - typedef struct _DATA { CRITICAL_SECTION cs; } DATA; diff --git a/docs/code-quality/c26800.md b/docs/code-quality/c26800.md index 429582775cb..9e0328095ee 100644 --- a/docs/code-quality/c26800.md +++ b/docs/code-quality/c26800.md @@ -20,7 +20,6 @@ Code analysis name: `USE_OF_A_MOVED_FROM_OBJECT` The following code will generate C26800. ```cpp - #include struct X { @@ -45,7 +44,6 @@ void test() { The following code won't generate C26800. ```cpp - #include struct MoveOnly { diff --git a/docs/code-quality/c26810.md b/docs/code-quality/c26810.md index 514d1fa2fb8..903b6d4d0c3 100644 --- a/docs/code-quality/c26810.md +++ b/docs/code-quality/c26810.md @@ -20,7 +20,6 @@ Code analysis name: `COROUTINES_USE_AFTER_FREE_CAPTURE` The following code will generate C26810. ```cpp - #include #include diff --git a/docs/code-quality/c26811.md b/docs/code-quality/c26811.md index dd2f168d03c..9e2d4808d3a 100644 --- a/docs/code-quality/c26811.md +++ b/docs/code-quality/c26811.md @@ -20,7 +20,6 @@ Code analysis name: `COROUTINES_USE_AFTER_FREE_PARAM` The following code will generate C26811. ```cpp - #include #include diff --git a/docs/code-quality/c26828.md b/docs/code-quality/c26828.md index ef41a171619..ee3f102c2c2 100644 --- a/docs/code-quality/c26828.md +++ b/docs/code-quality/c26828.md @@ -20,7 +20,6 @@ Code analysis name: `MIXING_OVERLAPPING_ENUMS` The following sample code causes warning C26828: ```cpp - enum BitWiseA { A = 1, @@ -45,7 +44,6 @@ int overlappingBitwiseEnums(BitWiseA a) To fix the warning, make sure enumeration types designed for use together have no overlapping values. Or, make sure all the related options are in a single enumeration type. ```cpp - enum BitWiseA { A = 1, diff --git a/docs/code-quality/c6029.md b/docs/code-quality/c6029.md index 02a767a1afe..6638b8912dd 100644 --- a/docs/code-quality/c6029.md +++ b/docs/code-quality/c6029.md @@ -23,7 +23,6 @@ Code analysis name: `USING_TAINTED_DATA` The following code generates this warning by calling the annotated function [`ReadFile`](/windows/desktop/api/fileapi/nf-fileapi-readfile) two times. After the first call, the Post attribute property marks the second parameter value untrusted. Therefore, passing an untrusted value in the second call to `ReadFile` generates this warning as shown in the following code: ```cpp - #include "windows.h" bool f(HANDLE hFile) diff --git a/docs/code-quality/c6053.md b/docs/code-quality/c6053.md index a7914014ba5..06943ee97c1 100644 --- a/docs/code-quality/c6053.md +++ b/docs/code-quality/c6053.md @@ -23,7 +23,6 @@ Code analysis name: `MISSING_ZERO_TERMINATION1` The following sample code generates this warning: ```cpp - #include #define MAX 15 @@ -40,7 +39,6 @@ size_t f( ) To correct this warning, zero-terminate the string as shown in the following sample code: ```cpp - #include #define MAX 15 @@ -58,7 +56,6 @@ size_t f( ) The following sample code corrects this warning using safe string manipulation `strncpy_s` function: ```cpp - #include #define MAX 15 diff --git a/docs/code-quality/c6387.md b/docs/code-quality/c6387.md index 7884265fd52..d96f377b6d6 100644 --- a/docs/code-quality/c6387.md +++ b/docs/code-quality/c6387.md @@ -21,7 +21,6 @@ Code analysis name: `INVALID_PARAM_VALUE_1` The following code generates this warning because a null parameter is passed to `f(char *)`: ```cpp - #include _Post_ _Null_ char * g(); @@ -38,7 +37,6 @@ void main() To correct this warning, use the following code: ```cpp - #include _Post_ _Notnull_ char * g(); diff --git a/docs/code-quality/understanding-sal.md b/docs/code-quality/understanding-sal.md index 198aed73359..8669d1689b4 100644 --- a/docs/code-quality/understanding-sal.md +++ b/docs/code-quality/understanding-sal.md @@ -20,7 +20,6 @@ Simply stated, SAL is an inexpensive way to let the compiler check your code for SAL can help you make your code design more understandable, both for humans and for code analysis tools. Consider this example that shows the C runtime function `memcpy`: ```cpp - void * memcpy( void *dest, const void *src, @@ -42,7 +41,6 @@ The documentation contains a couple of bits of information that suggest that you However, the compiler can't read the documentation or informal comments. It doesn't know that there is a relationship between the two buffers and `count`, and it also can't effectively guess about a relationship. SAL could provide more clarity about the properties and implementation of the function, as shown here: ```cpp - void * memcpy( _Out_writes_bytes_all_(count) void *dest, _In_reads_bytes_(count) const void *src, @@ -53,7 +51,6 @@ void * memcpy( Notice that these annotations resemble the information in the documentation, but they are more concise and they follow a semantic pattern. When you read this code, you can quickly understand the properties of this function and how to avoid buffer overrun security issues. Even better, the semantic patterns that SAL provides can improve the efficiency and effectiveness of automated code analysis tools in the early discovery of potential bugs. Imagine that someone writes this buggy implementation of `wmemcpy`: ```cpp - wchar_t * wmemcpy( _Out_writes_all_(count) wchar_t *dest, _In_reads_(count) const wchar_t *src, @@ -155,7 +152,6 @@ If you use Visual Studio Code Analysis on this example, it validates that the ca `_In_opt_` is the same as `_In_`, except that the input parameter is allowed to be NULL and, therefore, the function should check for this. ```cpp - void GoodInOptCallee(_In_opt_ int *pInt) { if(pInt != NULL) { diff --git a/docs/code-quality/using-rule-sets-to-specify-the-cpp-rules-to-run.md b/docs/code-quality/using-rule-sets-to-specify-the-cpp-rules-to-run.md index 6591618fe17..545b52d1840 100644 --- a/docs/code-quality/using-rule-sets-to-specify-the-cpp-rules-to-run.md +++ b/docs/code-quality/using-rule-sets-to-specify-the-cpp-rules-to-run.md @@ -229,7 +229,6 @@ The following ruleset schema describes the XML schema of a ruleset file. The rul - ``` Schema element details: diff --git a/docs/cpp/arrays-cpp.md b/docs/cpp/arrays-cpp.md index 941b90493e9..79ca8849569 100644 --- a/docs/cpp/arrays-cpp.md +++ b/docs/cpp/arrays-cpp.md @@ -52,7 +52,6 @@ You may require an array that's too large to allocate on the stack, or whose siz The following example shows how to define an array on the heap at run time. It shows how to access the array elements using the subscript operator and by using pointer arithmetic: ```cpp - void do_something(size_t size) { // Declare an array of doubles to be allocated on the heap @@ -104,7 +103,6 @@ int main() { do_something(108); } - ``` ## Initializing arrays diff --git a/docs/cpp/cpp-type-system-modern-cpp.md b/docs/cpp/cpp-type-system-modern-cpp.md index 2524e45e38a..3149ee6e375 100644 --- a/docs/cpp/cpp-type-system-modern-cpp.md +++ b/docs/cpp/cpp-type-system-modern-cpp.md @@ -78,7 +78,6 @@ The **`void`** type is a special type; you cannot declare a variable of type **` Any built-in or user-defined type may be qualified by the const keyword. Additionally, member functions may be **`const`**-qualified and even **`const`**-overloaded. The value of a **`const`** type cannot be modified after it is initialized. ```cpp - const double PI = 3.1415; PI = .75 //Error. Cannot modify const variable. ``` diff --git a/docs/cpp/functions-cpp.md b/docs/cpp/functions-cpp.md index a1b57135b7b..92f56686bdf 100644 --- a/docs/cpp/functions-cpp.md +++ b/docs/cpp/functions-cpp.md @@ -195,7 +195,6 @@ void DoSomething(const std::string&& input){...} A function declared with the single keyword **`void`** in the parameter declaration list takes no arguments, as long as the keyword **`void`** is the first and only member of the argument declaration list. Arguments of type **`void`** elsewhere in the list produce errors. For example: ```cpp - // OK same as GetTickCount() long GetTickCount( void ); ``` diff --git a/docs/cpp/object-lifetime-and-resource-management-modern-cpp.md b/docs/cpp/object-lifetime-and-resource-management-modern-cpp.md index a36c0eaff6b..b13d412b966 100644 --- a/docs/cpp/object-lifetime-and-resource-management-modern-cpp.md +++ b/docs/cpp/object-lifetime-and-resource-management-modern-cpp.md @@ -53,7 +53,6 @@ void functionUsingWidget() { w.do_something(); } // automatic destruction and deallocation for w and w.data - ``` Since C++11, there's a better way to write the previous example: by using a smart pointer from the standard library. The smart pointer handles the allocation and deletion of the memory it owns. Using a smart pointer eliminates the need for an explicit destructor in the `widget` class. diff --git a/docs/cpp/raw-pointers.md b/docs/cpp/raw-pointers.md index 2e8bcaf0921..7e4df62435a 100644 --- a/docs/cpp/raw-pointers.md +++ b/docs/cpp/raw-pointers.md @@ -232,7 +232,6 @@ A pointer to **`void`** simply points to a raw memory location. Sometimes it's n When a typed pointer is cast to a `void` pointer, the contents of the memory location are unchanged. However, the type information is lost, so that you can't do increment or decrement operations. A memory location can be cast, for example, from `MyClass*` to `void*` and back again to `MyClass*`. Such operations are inherently error-prone and require great care to avoid errors. Modern C++ discourages the use of `void` pointers in almost all circumstances. ```cpp - //func.c void func(void* data, int length) { diff --git a/docs/cpp/welcome-back-to-cpp-modern-cpp.md b/docs/cpp/welcome-back-to-cpp-modern-cpp.md index d8e01d7140c..9588b539758 100644 --- a/docs/cpp/welcome-back-to-cpp-modern-cpp.md +++ b/docs/cpp/welcome-back-to-cpp-modern-cpp.md @@ -37,7 +37,6 @@ void functionUsingWidget() { w.do_something(); // ... } // automatic destruction and deallocation for w and w.data - ``` Whenever possible, use a smart pointer to manage heap memory. If you must use the **`new`** and **`delete`** operators explicitly, follow the principle of RAII. For more information, see [Object lifetime and resource management (RAII)](object-lifetime-and-resource-management-modern-cpp.md). diff --git a/docs/cppcx/back-inserter-function.md b/docs/cppcx/back-inserter-function.md index 7e0f7a15e45..0860f65804f 100644 --- a/docs/cppcx/back-inserter-function.md +++ b/docs/cppcx/back-inserter-function.md @@ -13,7 +13,6 @@ Returns an iterator that is used to insert elements at the end of the specified ## Syntax ``` - template Platform::BackInsertIterator back_inserter(IVector^ v); diff --git a/docs/cppcx/operator-type-hat.md b/docs/cppcx/operator-type-hat.md index d1caf776f9b..658cfdad71f 100644 --- a/docs/cppcx/operator-type-hat.md +++ b/docs/cppcx/operator-type-hat.md @@ -31,7 +31,6 @@ rootFrame->Navigate(TypeName(MainPage::typeid), e->Arguments); The next example shows how to convert between `TypeName` and `Type`. ``` - // Convert from Type to TypeName TypeName tn = TypeName(MainPage::typeid); diff --git a/docs/cppcx/platform-collections-mapview-class.md b/docs/cppcx/platform-collections-mapview-class.md index 67ca96405de..2f166b244ed 100644 --- a/docs/cppcx/platform-collections-mapview-class.md +++ b/docs/cppcx/platform-collections-mapview-class.md @@ -90,7 +90,6 @@ Determines whether the current MapView contains the specified key. ### Syntax ``` - bool HasKey(K key); ``` diff --git a/docs/cppcx/platform-collections-vectoriterator-class.md b/docs/cppcx/platform-collections-vectoriterator-class.md index f6a5f656603..fca04535963 100644 --- a/docs/cppcx/platform-collections-vectoriterator-class.md +++ b/docs/cppcx/platform-collections-vectoriterator-class.md @@ -96,7 +96,6 @@ Decrements the current VectorIterator. ### Syntax ``` - VectorIterator& operator--(); VectorIterator operator--(int); ``` @@ -267,7 +266,6 @@ Subtracts either a specified number of elements from the current iterator yieldi ### Syntax ``` - VectorIterator operator-(difference_type n) const; difference_type operator-(const VectorIterator& other) const; @@ -311,7 +309,6 @@ Returns a VectorIterator that references the element at the specified displaceme ### Syntax ``` - VectorIterator operator+(difference_type n); template diff --git a/docs/cppcx/platform-collections-vectorview-class.md b/docs/cppcx/platform-collections-vectorview-class.md index 9bbc63a3227..5fe72ec39f4 100644 --- a/docs/cppcx/platform-collections-vectorview-class.md +++ b/docs/cppcx/platform-collections-vectorview-class.md @@ -65,7 +65,6 @@ Returns an iterator that specifies the first element in the VectorView. ### Syntax ``` - virtual Windows::Foundation::Collections::IIterator^ First(); ``` @@ -85,7 +84,6 @@ Retrieves the element of the current VectorView that is indicated by the specifi ### Syntax ``` - T GetAt( UInt32 index ); @@ -107,7 +105,6 @@ Retrieves a sequence of items from the current VectorView, starting at the speci ### Syntax ``` - virtual unsigned int GetMany( unsigned int startIndex, ::Platform::WriteOnlyArray^ dest @@ -133,7 +130,6 @@ Searches for the specified item in the current VectorView, and if found, returns ### Syntax ``` - virtual bool IndexOf( T value, unsigned int* index @@ -161,7 +157,6 @@ Returns the number of elements in the current VectorView object. ### Syntax ``` - virtual property unsigned int Size; ``` diff --git a/docs/cppcx/platform-collections-vectorviewiterator-class.md b/docs/cppcx/platform-collections-vectorviewiterator-class.md index 9e58635be0e..9abe5629996 100644 --- a/docs/cppcx/platform-collections-vectorviewiterator-class.md +++ b/docs/cppcx/platform-collections-vectorviewiterator-class.md @@ -150,7 +150,6 @@ Indicates whether the current VectorViewIterator is greater than a specified Vec ### Syntax ``` - bool operator>(const VectorViewIterator& other) const; ``` @@ -170,7 +169,6 @@ Indicates whether the current `VectorViewIterator` is greater than or equal to t ### Syntax ``` - bool operator>=(const VectorViewIterator& other) const; ``` @@ -190,7 +188,6 @@ Increments the current VectorViewIterator. ### Syntax ``` - VectorViewIterator& operator++(); VectorViewIterator operator++(int); ``` @@ -250,7 +247,6 @@ Indicates whether the current `VectorIterator` is less than or equal to a specif ### Syntax ``` - bool operator<=(const VectorViewIterator& other) const; ``` @@ -270,7 +266,6 @@ Subtracts either a specified number of elements from the current iterator yieldi ### Syntax ``` - VectorViewIterator operator-(difference_type n) const; difference_type operator-(const VectorViewIterator& other) const; @@ -314,7 +309,6 @@ Returns a VectorViewIterator that references the element at the specified displa ### Syntax ``` - VectorViewIterator operator+(difference_type n) const; template @@ -385,7 +379,6 @@ Initializes a new instance of the VectorViewIterator class. ### Syntax ``` - VectorViewIterator(); explicit VectorViewIterator( diff --git a/docs/cppcx/threading-and-marshaling-c-cx.md b/docs/cppcx/threading-and-marshaling-c-cx.md index 2289aa48776..3ddf3dd4991 100644 --- a/docs/cppcx/threading-and-marshaling-c-cx.md +++ b/docs/cppcx/threading-and-marshaling-c-cx.md @@ -31,7 +31,6 @@ For various reasons, some classes can't be agile. If you are accessing instances Of the non-agile classes, the easiest to deal with are those that have `ThreadingModel`=Both and `MarshallingType`=Standard. You can make these classes agile just by using the `Agile` helper class. The following example shows a declaration of a non-agile object of type `Windows::Security::Credentials::UI::CredentialPickerOptions^`, and the compiler warning that's issued as a result. ``` - ref class MyOptions { public: @@ -63,7 +62,6 @@ If neither of those conditions apply, then you can mark the containing class as The following example shows how to use `Agile` so that you can safely ignore the warning. ``` - #include ref class MyOptions { diff --git a/docs/cppcx/value-classes-and-structs-c-cx.md b/docs/cppcx/value-classes-and-structs-c-cx.md index 9dbebf73e1c..4c4cd2cdc80 100644 --- a/docs/cppcx/value-classes-and-structs-c-cx.md +++ b/docs/cppcx/value-classes-and-structs-c-cx.md @@ -12,7 +12,6 @@ A *value struct* or *value class* is a Windows Runtime-compatible POD ("plain ol The following examples show how to declare and initialize value structs. ``` - // in mainpage.xaml.h: value struct TestStruct { @@ -125,7 +124,6 @@ bool MainPage::IsCurrentlyEnrolled(Student s) A value struct itself may be made nullable in the same way, as shown here: ``` - public value struct MyStruct { public: diff --git a/docs/cppcx/weak-references-and-breaking-cycles-c-cx.md b/docs/cppcx/weak-references-and-breaking-cycles-c-cx.md index 6ec20f173f4..b3ec2de1dd1 100644 --- a/docs/cppcx/weak-references-and-breaking-cycles-c-cx.md +++ b/docs/cppcx/weak-references-and-breaking-cycles-c-cx.md @@ -11,7 +11,6 @@ In any type system that's based on reference-counting, references to types can f One scenario in which `WeakReference` must be used is when the **`this`** pointer is captured in a lambda expression that's used to define an event handler. We recommend that you use named methods when you define event handlers, but if you want to use a lambda for your event handler—or if you have to break a reference counting cycle in some other situation—use `WeakReference`. Here's an example: ``` - using namespace Platform::Details; using namespace Windows::UI::Xaml; using namespace Windows::UI::Xaml::Input; diff --git a/docs/cppcx/windows-foundation-collections-namespace-c-cx.md b/docs/cppcx/windows-foundation-collections-namespace-c-cx.md index e9f90569667..4bfd12a620d 100644 --- a/docs/cppcx/windows-foundation-collections-namespace-c-cx.md +++ b/docs/cppcx/windows-foundation-collections-namespace-c-cx.md @@ -13,7 +13,6 @@ C++/CX supplements the Windows::Foundation::Collections namespace with functions ## Syntax ``` - namespace Windows { namespace Foundation { namespace Collections; diff --git a/docs/error-messages/tool-errors/linker-tools-warning-lnk4217.md b/docs/error-messages/tool-errors/linker-tools-warning-lnk4217.md index 5c414ede438..94497411316 100644 --- a/docs/error-messages/tool-errors/linker-tools-warning-lnk4217.md +++ b/docs/error-messages/tool-errors/linker-tools-warning-lnk4217.md @@ -29,7 +29,6 @@ int main() func(); return 0; } - ``` And then, diff --git a/docs/ide/lnt-logical-bitwise-mismatch.md b/docs/ide/lnt-logical-bitwise-mismatch.md index 9104b18bf1c..c501a731b4d 100644 --- a/docs/ide/lnt-logical-bitwise-mismatch.md +++ b/docs/ide/lnt-logical-bitwise-mismatch.md @@ -23,7 +23,6 @@ void example(bool a, bool b) { bool c = a & b; // Flagged: Bitwise AND operator used with Boolean variables. bool d = a || b; // OK: Logical OR operator used with Boolean variables. } - ``` Only use bitwise operators on integer values. diff --git a/docs/mfc/reference/cmfcribbonpanel-class.md b/docs/mfc/reference/cmfcribbonpanel-class.md index ae0c4cf2d40..2a81fe3a7a0 100644 --- a/docs/mfc/reference/cmfcribbonpanel-class.md +++ b/docs/mfc/reference/cmfcribbonpanel-class.md @@ -968,7 +968,6 @@ If you want to add a custom element (for example, a color button) to the ribbon The following example shows how to use the `SetElementRTCByID` method: ``` - // Load and add toolbar with standard buttons. This toolbar // should display a custom color button with id ID_CHAR_COLOR: diff --git a/docs/mfc/reference/dao-database-engine-initialization-and-termination.md b/docs/mfc/reference/dao-database-engine-initialization-and-termination.md index ab7e957bd30..67e0826e34d 100644 --- a/docs/mfc/reference/dao-database-engine-initialization-and-termination.md +++ b/docs/mfc/reference/dao-database-engine-initialization-and-termination.md @@ -21,7 +21,6 @@ DAO is used with Access databases and is supported through Office 2013. DAO 3.6 This function initializes the DAO database engine. ``` - void AfxDaoInit(); throw(CDaoException*); @@ -42,7 +41,6 @@ For related information, and for an example of calling `AfxDaoInit`, see [Techni This function terminates the DAO database engine. ``` - void AfxDaoTerm(); ``` diff --git a/docs/mfc/reference/event-sink-maps.md b/docs/mfc/reference/event-sink-maps.md index e8d550c045a..bfaaba81ce9 100644 --- a/docs/mfc/reference/event-sink-maps.md +++ b/docs/mfc/reference/event-sink-maps.md @@ -248,7 +248,6 @@ For a list of the **VTS_** constants, see [EVENT_CUSTOM](event-maps.md#event_cus Use the ON_PROPNOTIFY_RANGE macro to define an event sink map entry for handling property notifications from any OLE control having a control ID within a contiguous range of IDs. ``` - ON_PROPNOTIFY_RANGE(theClass, idFirst, idLast, dispid, pfnRequest, pfnChanged) ``` @@ -281,7 +280,6 @@ Pointer to a member function that handles the `OnChanged` notification for this The ON_PROPNOTIFY_REFLECT macro, when used in the event sink map of an OLE control's wrapper class, receives property notifications sent by the control before they are handled by the control's container. ``` - ON_PROPNOTIFY_REFLECT(theClass, dispid, pfnRequest, pfnChanged) ``` diff --git a/docs/mfc/tn028-context-sensitive-help-support.md b/docs/mfc/tn028-context-sensitive-help-support.md index 1a5ff078b5a..09992516214 100644 --- a/docs/mfc/tn028-context-sensitive-help-support.md +++ b/docs/mfc/tn028-context-sensitive-help-support.md @@ -74,7 +74,6 @@ To override this functionality and the way that a Help context is determined, yo ## WM_COMMANDHELP ``` - afx_msg LRESULT CWnd::OnCommandHelp(WPARAM wParam, LPARAM lParam) ``` @@ -103,7 +102,6 @@ If the user chooses a command from the menu, it is handled as help on that comma ## WM_HELPHITTEST ``` - afx_msg LRESULT CWnd::OnHelpHitTest( WPARAM, LPARAM lParam) ``` diff --git a/docs/overview/cpp-conformance-improvements-2019.md b/docs/overview/cpp-conformance-improvements-2019.md index 1ca2fe0e0ce..dd545856d13 100644 --- a/docs/overview/cpp-conformance-improvements-2019.md +++ b/docs/overview/cpp-conformance-improvements-2019.md @@ -779,7 +779,6 @@ struct Comparer { return a.a < b.a; } }; - ``` ## Conformance improvements in Visual Studio 2019 version 16.3 diff --git a/docs/parallel/openmp/2-directives.md b/docs/parallel/openmp/2-directives.md index b949f5b496f..6ff80f4fbb6 100644 --- a/docs/parallel/openmp/2-directives.md +++ b/docs/parallel/openmp/2-directives.md @@ -798,7 +798,6 @@ The restrictions to the `reduction` clause are as follows: The `copyin` clause provides a mechanism to assign the same value to `threadprivate` variables for each thread in the team executing the parallel region. For each variable specified in a `copyin` clause, the value of the variable in the master thread of the team is copied, as if by assignment, to the thread-private copies at the beginning of the parallel region. The syntax of the `copyin` clause is as follows: ```cpp - copyin( variable-list ) @@ -817,7 +816,6 @@ The `copyprivate` clause provides a mechanism to use a private variable to broad The syntax of the `copyprivate` clause is as follows: ```cpp - copyprivate( variable-list ) diff --git a/docs/standard-library/algorithm-functions.md b/docs/standard-library/algorithm-functions.md index a2c9283ea46..17712e778e3 100644 --- a/docs/standard-library/algorithm-functions.md +++ b/docs/standard-library/algorithm-functions.md @@ -1305,6 +1305,7 @@ int main() equal_range_demo( v2, "fred" ); equal_range_demo( v2, "fred", shorter_than, "shorter_than" ); } + ``` ```Output @@ -1336,8 +1337,7 @@ Vector sorted by the binary predicate shorter_than: fun cute blah fluffy kittens meowmeowmeow Result of equal_range with value = fred: - fun [ cute blah ] fluffy kittens meowmeowmeow - + fun [ cute blah ] fluffy kittens meowmeowmeow ``` ## `fill` diff --git a/docs/standard-library/basic-ios-class.md b/docs/standard-library/basic-ios-class.md index c5682baed39..28cdc9a600c 100644 --- a/docs/standard-library/basic-ios-class.md +++ b/docs/standard-library/basic-ios-class.md @@ -13,7 +13,6 @@ The class template describes the storage and member functions common to both inp ## Syntax ```cpp - template class basic_ios : public ios_base ``` diff --git a/docs/standard-library/memory-functions.md b/docs/standard-library/memory-functions.md index 084121f88e6..7476c9e8b9b 100644 --- a/docs/standard-library/memory-functions.md +++ b/docs/standard-library/memory-functions.md @@ -982,7 +982,6 @@ template void swap( weak_ptr& left, weak_ptr& right) noexcept; - ``` ### Parameters diff --git a/docs/standard-library/string-view-operators.md b/docs/standard-library/string-view-operators.md index ee8386d9e7b..cc6f5a702b3 100644 --- a/docs/standard-library/string-view-operators.md +++ b/docs/standard-library/string-view-operators.md @@ -301,7 +301,6 @@ Constructs a `string_view` from a string literal. Requires namespace `std::liter ### Example ```cpp - using namespace std; using namespace literals::string_view_literals; From 8b3faebd8b04514b1576f2a8eb2c8ce2414ea819 Mon Sep 17 00:00:00 2001 From: Colin Robertson <3836425+corob-msft@users.noreply.github.com> Date: Thu, 3 Nov 2022 18:31:15 -0700 Subject: [PATCH 2/5] Fix stray characters --- docs/atl/reference/iperpropertybrowsingimpl-class.md | 2 +- docs/standard-library/algorithm-functions.md | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/atl/reference/iperpropertybrowsingimpl-class.md b/docs/atl/reference/iperpropertybrowsingimpl-class.md index cc1e9a5a450..c5f0e2678ed 100644 --- a/docs/atl/reference/iperpropertybrowsingimpl-class.md +++ b/docs/atl/reference/iperpropertybrowsingimpl-class.md @@ -15,7 +15,7 @@ This class implements `IUnknown` and allows a client to access the information i ## Syntax -```cpp +``` template class ATL_NO_VTABLE IPerPropertyBrowsingImpl : public IPerPropertyBrowsing diff --git a/docs/standard-library/algorithm-functions.md b/docs/standard-library/algorithm-functions.md index 17712e778e3..0513578df12 100644 --- a/docs/standard-library/algorithm-functions.md +++ b/docs/standard-library/algorithm-functions.md @@ -1305,7 +1305,6 @@ int main() equal_range_demo( v2, "fred" ); equal_range_demo( v2, "fred", shorter_than, "shorter_than" ); } - ``` ```Output From 743d888814f97e792e5b41a78f0dc1bed58595c7 Mon Sep 17 00:00:00 2001 From: TylerMSFT Date: Fri, 4 Nov 2022 18:25:23 -0700 Subject: [PATCH 3/5] call out istream_view and wistream_view better --- .../standard-library/basic-istream-view-class.md | 16 +++++++++------- docs/standard-library/iota-view-class.md | 7 +++---- docs/standard-library/view-classes.md | 4 ++-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/docs/standard-library/basic-istream-view-class.md b/docs/standard-library/basic-istream-view-class.md index 3571b5ef5fc..2b112399c86 100644 --- a/docs/standard-library/basic-istream-view-class.md +++ b/docs/standard-library/basic-istream-view-class.md @@ -1,9 +1,9 @@ --- title: "basic_istream_view class (C++ Standard Library)| Microsoft Docs" -description: "API reference for the Standard Template Library (STL) basic_istream_view class, which reads (using operator>>) successive elements from an input stream." -ms.date: 09/27/2022 -f1_keywords: ["ranges/std::basic_istream_view", "ranges/std::basic_istream_view::base", "ranges/std::basic_istream_view::begin", "ranges/std::basic_istream_view::data", "ranges/std::basic_istream_view::empty", "ranges/std::basic_istream_view::end", "ranges/std::basic_istream_view::size", "ranges/std::basic_istream_view::operator bool", "ranges/std::basic_istream_view::back", "ranges/std::basic_istream_view::front", "ranges/std::basic_istream_view::operator[]"] -helpviewer_keywords: ["std::ranges::basic_istream_view [C++]", "std::ranges::basic_istream_view::base [C++]", "std::ranges::basic_istream_view::begin [C++]", "std::ranges::basic_istream_view::data [C++]", "std::ranges::basic_istream_view::empty [C++]", "std::ranges::basic_istream_view::end [C++]", "std::ranges::basic_istream_view::size [C++]", "std::ranges::basic_istream_view::back [C++]", "std::ranges::basic_istream_view::front [C++]", "std::ranges::basic_istream_view::operator[] [C++]", "std::ranges::basic_istream_view::operator bool [C++]"] +description: "API reference for the Standard Template Library (STL) basic_istream_view class, which reads (using operator>>) successive elements from an input stream. Also includes the istream_view and wistream_view specializations." +ms.date: 11/04/2022 +f1_keywords: ["ranges/std::basic_istream_view", "ranges/std::istream_view", "ranges/std::wistream_view", "ranges/std::basic_istream_view::begin", "ranges/std::basic_istream_view::end", "ranges/std::istream_view::begin", "ranges/std::istream_view::end", "ranges/std::wistream_view::begin", "ranges/std::wistream_view::end"] +helpviewer_keywords: ["std::ranges::basic_istream_view [C++]", "std::ranges::istream_view [C++]", "std::ranges::wistream_view [C++]", "std::ranges::basic_istream_view::base [C++]", "std::ranges::basic_istream_view::begin [C++]", "std::ranges::basic_istream_view::end [C++]", ] dev_langs: ["C++"] --- # `basic_istream_view` class (C++ Standard Library) @@ -55,7 +55,7 @@ For a description of the following entries, see [View class characteristics](vie | **Common range** | No | | **Borrowed range** | No | -## Specializations +## Specializations:`istream_view` and `wistream_view` Convenience alias templates are provided for `char` and `wchar_t` streams, as follows: @@ -114,7 +114,9 @@ A `basic_istream_view` instance. The `basic_istream_view` internal stream pointe The best way to create a `basic_istream_view` is by using the [`views::istream`](range-adaptors.md#istream) range adaptor. Range adaptors are the intended way to create view classes. The view types are exposed in case you want to create your own custom view type. -### Example: `basic_istream_view` +### Example: `basic_istream_view`, `istream_view`, and `wistream_view` + +```cpp ```cpp // requires /std:c++20 or later @@ -152,7 +154,7 @@ int main() // specify all template arguments std::wistringstream misc(L"S T L"); - std::ranges::basic_istream_view> basic{ misc }; + std::ranges::basic_istream_view> basic{misc}; for (const auto& elem : basic) { std::wcout << elem << ' '; // STL diff --git a/docs/standard-library/iota-view-class.md b/docs/standard-library/iota-view-class.md index 931a60e2511..250983766e0 100644 --- a/docs/standard-library/iota-view-class.md +++ b/docs/standard-library/iota-view-class.md @@ -1,7 +1,7 @@ --- title: "iota_view class (C++ Standard Library)| Microsoft Docs" description: "API reference for the Standard Template Library (STL) iota_view class: a factory that generates a view from a bounded or unbounded series of repeatedly incrementing values." -ms.date: 10/14/2022 +ms.date: 11/04/2022 f1_keywords: ["ranges/std::iota_view", "ranges/std::iota_view::base", "ranges/std::iota_view::begin", "ranges/std::iota_view::end", "ranges/std::iota_view::size", "ranges/std::iota_view::empty", "ranges/std::iota_view::operator bool", "ranges/std::iota_view::back", "ranges/std::iota_view::front", "ranges/std::iota_view::operator[]"] helpviewer_keywords: ["std::ranges::iota_view [C++]", "std::ranges::iota_view [C++], base", "std::ranges::iota_view [C++], begin", "std::ranges::iota_view [C++], end", "std::ranges::iota_view [C++], size", "std::ranges::iota_view [C++], empty", "std::ranges::iota_view [C++], operator bool", "std::ranges::iota_view [C++], front", "std::ranges::iota_view [C++], back", "std::ranges::iota_view [C++], operator[]"] dev_langs: ["C++"] @@ -124,13 +124,12 @@ int main() { std::ranges::iota_view iv; // create an iota_view with an unbounded range, starting at 0 std::ranges::iota_view iv2(5); // create an iota_view with an unbounded range, starting at 5. - std::ranges::iota_view iv3{ 5, 10 }; // create an iota_view with a bounded range, starting at 5 and ending at 9 + std::ranges::iota_view iv3{5, 10}; // create an iota_view with a bounded range, starting at 5 and ending at 9 std::vector v{10, 20, 35, 45, 50, 66, 77, 82, 90, 100}; auto start = std::ranges::find(v, 35); auto end = std::ranges::find(v, 82); - auto iv4 = std::ranges::iota_view(start, end); - for (auto &&val : iv4) + for (auto &&val : std::ranges::iota_view(start, end)) { std::cout << *val << ' '; // outputs 35 45 50 66 77 } diff --git a/docs/standard-library/view-classes.md b/docs/standard-library/view-classes.md index 68292070512..b5f9ccc8e0f 100644 --- a/docs/standard-library/view-classes.md +++ b/docs/standard-library/view-classes.md @@ -1,7 +1,7 @@ --- description: "Learn more about view classes, which allow you to inexpensively refer to and transform ranges." title: "View classes" -ms.date: 10/07/2022 +ms.date: 11/04/2022 f1_keywords: ["RANGES/std::ranges::views", "RANGES/std::views"] helpviewer_keywords: ["RANGES/VIEWS/std", "VIEWS/std"] --- @@ -100,7 +100,7 @@ The following view classes are defined in the `std::ranges` namespace. | View | Description | |--|--| -| [`basic_istream_view`](basic-istream-view-class.md)C++20 | A view of successive elements from an input stream. | +| [`basic_istream_view`](basic-istream-view-class.md)C++20 | A view of successive elements from an input stream. Includes `istream_view` and `wistream_view`. | | [`common_view`](common-view-class.md)C++20 | Adapts a view that has different iterator/sentinel types into a view with the same iterator/sentinel types. | | [`drop_view`](drop-view-class.md)C++20 | Created from another view, skipping the first `count` elements. | | [`drop_while_view`](drop-while-view-class.md)C++20 | Created from another view, skipping leading elements as long as a predicate holds. | From 607ada2a50b073f45308bc169e56855e20653c9c Mon Sep 17 00:00:00 2001 From: TylerMSFT Date: Sat, 5 Nov 2022 09:39:54 -0700 Subject: [PATCH 4/5] tighten up error section --- docs/standard-library/range-concepts.md | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/docs/standard-library/range-concepts.md b/docs/standard-library/range-concepts.md index 7d10fe265db..30818a5e0b5 100644 --- a/docs/standard-library/range-concepts.md +++ b/docs/standard-library/range-concepts.md @@ -48,22 +48,7 @@ int main() } ``` -Using Visual Studio 2022, version 17.4p4, the errors generated for the preceding example are: - -```output -example.cpp -example.cpp(31): error C7602: 'DivideEmUp': the associated constraints are not satisfied -example.cpp(18): note: see declaration of 'DivideEmUp' -example.cpp(16): note: the concept 'dividable' evaluated to false -example.cpp(9): note: the expression is invalid -example.cpp(31): error C2641: cannot deduce template arguments for 'DivideEmUp' -example.cpp(31): error C2783: 'DivideEmUp DivideEmUp(void)': could not deduce template argument for 'T' -example.cpp(18): note: see declaration of 'DivideEmUp' -example.cpp(31): error C2780: 'DivideEmUp DivideEmUp(DivideEmUp)': expects 1 arguments - 0 provided -example.cpp(18): note: see declaration of 'DivideEmUp' -``` - -If you specify the compiler switch `/diagnostics:caret`, then one of the errors is concept `dividable` evaluated to false. It even points directly to the expression requirement `(a / b)` that failed. +When you pass the compiler switch `/diagnostics:caret` to Visual Studio 2022 version 17.4p4 or later, the error that concept `dividable` evaluated to false will even point directly to the expression requirement `(a / b)` that failed. The following concepts are defined in `std::ranges` and are declared in the `` header file. They're used in the declarations of [range adaptors](range-adaptors.md), [views](view-classes.md), and so on. From 5a87bf0fa596c57d3135ea517794a66f15e43717 Mon Sep 17 00:00:00 2001 From: Colin Robertson <3836425+corob-msft@users.noreply.github.com> Date: Sun, 6 Nov 2022 01:45:45 -0700 Subject: [PATCH 5/5] Fix Acrolinx issues found in #4654 (#4657) --- docs/cpp/cpp-type-system-modern-cpp.md | 68 ++++++++++++++------------ 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/docs/cpp/cpp-type-system-modern-cpp.md b/docs/cpp/cpp-type-system-modern-cpp.md index 7399876dd00..ad5f425f45c 100644 --- a/docs/cpp/cpp-type-system-modern-cpp.md +++ b/docs/cpp/cpp-type-system-modern-cpp.md @@ -1,29 +1,33 @@ --- description: "Learn more about: C++ type system" title: "C++ type system" -ms.date: "11/19/2019" +ms.date: 11/04/2022 ms.topic: "conceptual" ms.assetid: 553c0ed6-77c4-43e9-87b1-c903eec53e80 --- # C++ type system -The concept of *type* is very important in C++. Every variable, function argument, and function return value must have a type in order to be compiled. Also, every expression (including literal values) is implicitly given a type by the compiler before it is evaluated. Some examples of types include **`int`** to store integer values, **`double`** to store floating-point values (also known as *scalar* data types), or the Standard Library class [std::basic_string](../standard-library/basic-string-class.md) to store text. You can create your own type by defining a **`class`** or **`struct`**. The type specifies the amount of memory that will be allocated for the variable (or expression result), the kinds of values that may be stored in that variable, how those values (as bit patterns) are interpreted, and the operations that can be performed on it. This article contains an informal overview of the major features of the C++ type system. +The concept of *type* is important in C++. Every variable, function argument, and function return value must have a type in order to be compiled. Also, all expressions (including literal values) are implicitly given a type by the compiler before they're evaluated. Some examples of types include built-in types such as **`int`** to store integer values, **`double`** to store floating-point values, or Standard Library types such as class [`std::basic_string`](../standard-library/basic-string-class.md) to store text. You can create your own type by defining a **`class`** or **`struct`**. The type specifies the amount of memory that's allocated for the variable (or expression result). The type also specifies the kinds of values that may be stored, how the compiler interprets the bit patterns in those values, and the operations you can perform on them. This article contains an informal overview of the major features of the C++ type system. ## Terminology -**Variable**: The symbolic name of a quantity of data so that the name can be used to access the data it refers to throughout the scope of the code where it is defined. In C++, *variable* is generally used to refer to instances of scalar data types, whereas instances of other types are usually called *objects*. +**Scalar type**: A type that holds a single value of a defined range. Scalars include arithmetic types (integral or floating-point values), enumeration type members, pointer types, pointer-to-member types, and `std::nullptr_t`. Fundamental types are typically scalar types. -**Object**: For simplicity and consistency, this article uses the term *object* to refer to any instance of a class or structure, and when it is used in the general sense includes all types, even scalar variables. +**Compound type**: A type that isn't a scalar type. Compound types include array types, function types, class (or struct) types, union types, enumerations, references, and pointers to non-static class members. + +**Variable**: The symbolic name of a quantity of data. The name can be used to access the data it refers to throughout the scope of the code where it's defined. In C++, *variable* is often used to refer to instances of scalar data types, whereas instances of other types are typically called *objects*. + +**Object**: For simplicity and consistency, this article uses the term *object* to refer to any instance of a class or structure. When it's used in the general sense, it includes all types, even scalar variables. **POD type** (plain old data): This informal category of data types in C++ refers to types that are scalar (see the Fundamental types section) or are *POD classes*. A POD class has no static data members that aren't also PODs, and has no user-defined constructors, user-defined destructors, or user-defined assignment operators. Also, a POD class has no virtual functions, no base class, and no private or protected non-static data members. POD types are often used for external data interchange, for example with a module written in the C language (which has POD types only). ## Specifying variable and function types -C++ is a *strongly typed* language and it is also *statically-typed*; every object has a type and that type never changes (not to be confused with static data objects). When you declare a variable in your code, you must either specify its type explicitly, or use the **`auto`** keyword to instruct the compiler to deduce the type from the initializer. When you declare a function in your code, you must specify the type of each argument and its return value, or **`void`** if no value is returned by the function. The exception is when you are using function templates, which allow for arguments of arbitrary types. +C++ is both a *strongly typed* language and a *statically typed* language; every object has a type and that type never changes. When you declare a variable in your code, you must either specify its type explicitly, or use the **`auto`** keyword to instruct the compiler to deduce the type from the initializer. When you declare a function in your code, you must specify the type of its return value and of each argument. Use the return value type **`void`** if no value is returned by the function. The exception is when you're using function templates, which allow for arguments of arbitrary types. -After you first declare a variable, you cannot change its type at some later point. However, you can copy the variable's value or a function's return value into another variable of a different type. Such operations are called *type conversions*, which are sometimes necessary but are also potential sources of data loss or incorrectness. +After you first declare a variable, you can't change its type at some later point. However, you can copy the variable's value or a function's return value into another variable of a different type. Such operations are called *type conversions*, which are sometimes necessary but are also potential sources of data loss or incorrectness. -When you declare a variable of POD type, we strongly recommend you initialize it, which means to give it an initial value. Until you initialize a variable, it has a "garbage" value that consists of whatever bits happened to be in that memory location previously. This is an important aspect of C++ to remember, especially if you are coming from another language that handles initialization for you. When declaring a variable of non-POD class type, the constructor handles initialization. +When you declare a variable of POD type, we strongly recommend you *initialize* it, which means to give it an initial value. Until you initialize a variable, it has a "garbage" value that consists of whatever bits happened to be in that memory location previously. It's an important aspect of C++ to remember, especially if you're coming from another language that handles initialization for you. When you declare a variable of non-POD class type, the constructor handles initialization. The following example shows some simple variable declarations with some descriptions for each. The example also shows how the compiler uses type information to allow or disallow certain subsequent operations on the variable. @@ -46,9 +50,9 @@ int maxValue; // Not recommended! maxValue contains ## Fundamental (built-in) types -Unlike some languages, C++ has no universal base type from which all other types are derived. The language includes many *fundamental types*, also known as *built-in types*. This includes numeric types such as **`int`**, **`double`**, **`long`**, **`bool`**, plus the **`char`** and **`wchar_t`** types for ASCII and UNICODE characters, respectively. Most integral fundamental types (except **`bool`**, **`double`**, **`wchar_t`**, and related types) all have **`unsigned`** versions, which modify the range of values that the variable can store. For example, an **`int`**, which stores a 32-bit signed integer, can represent a value from -2,147,483,648 to 2,147,483,647. An **`unsigned int`**, which is also stored as 32-bits, can store a value from 0 to 4,294,967,295. The total number of possible values in each case is the same; only the range is different. +Unlike some languages, C++ has no universal base type from which all other types are derived. The language includes many *fundamental types*, also known as *built-in types*. These types include numeric types such as **`int`**, **`double`**, **`long`**, **`bool`**, plus the **`char`** and **`wchar_t`** types for ASCII and UNICODE characters, respectively. Most integral fundamental types (except **`bool`**, **`double`**, **`wchar_t`**, and related types) all have **`unsigned`** versions, which modify the range of values that the variable can store. For example, an **`int`**, which stores a 32-bit signed integer, can represent a value from -2,147,483,648 to 2,147,483,647. An **`unsigned int`**, which is also stored as 32 bits, can store a value from 0 to 4,294,967,295. The total number of possible values in each case is the same; only the range is different. -The fundamental types are recognized by the compiler, which has built-in rules that govern what operations you can perform on them, and how they can be converted to other fundamental types. For a complete list of built-in types and their size and numeric limits, see [Built-in types](../cpp/fundamental-types-cpp.md). +The compiler recognizes these built-in types, and it has built-in rules that govern what operations you can perform on them, and how they can be converted to other fundamental types. For a complete list of built-in types and their size and numeric limits, see [Built-in types](../cpp/fundamental-types-cpp.md). The following illustration shows the relative sizes of the built-in types in the Microsoft C++ implementation: @@ -62,33 +66,33 @@ The following table lists the most frequently used fundamental types, and their | **`double`** | 8 bytes | The default choice for floating point values. | | **`bool`** | 1 byte | Represents values that can be either true or false. | | **`char`** | 1 byte | Use for ASCII characters in older C-style strings or std::string objects that will never have to be converted to UNICODE. | -| **`wchar_t`** | 2 bytes | Represents "wide" character values that may be encoded in UNICODE format (UTF-16 on Windows, other operating systems may differ). This is the character type that is used in strings of type `std::wstring`. | +| **`wchar_t`** | 2 bytes | Represents "wide" character values that may be encoded in UNICODE format (UTF-16 on Windows, other operating systems may differ). **`wchar_t`** is the character type that's used in strings of type `std::wstring`. | | **`unsigned char`** | 1 byte | C++ has no built-in byte type. Use **`unsigned char`** to represent a byte value. | | **`unsigned int`** | 4 bytes | Default choice for bit flags. | -| **`long long`** | 8 bytes | Represents very large integer values. | +| **`long long`** | 8 bytes | Represents a much larger range of integer values. | Other C++ implementations may use different sizes for certain numeric types. For more information on the sizes and size relationships that the C++ standard requires, see [Built-in types](fundamental-types-cpp.md). -## The void type +## The `void` type -The **`void`** type is a special type; you cannot declare a variable of type **`void`**, but you can declare a variable of type `void *` (pointer to **`void`**), which is sometimes necessary when allocating raw (un-typed) memory. However, pointers to **`void`** are not type-safe and generally their use is strongly discouraged in modern C++. In a function declaration, a **`void`** return value means that the function does not return a value; this is a common and acceptable use of **`void`**. While the C language required functions that have zero parameters to declare **`void`** in the parameter list, for example, `fou(void)`, this practice is discouraged in modern C++ and should be declared `fou()`. For more information, see [Type Conversions and Type Safety](../cpp/type-conversions-and-type-safety-modern-cpp.md). +The **`void`** type is a special type; you can't declare a variable of type **`void`**, but you can declare a variable of type `void *` (pointer to **`void`**), which is sometimes necessary when allocating raw (untyped) memory. However, pointers to **`void`** aren't type-safe and their use is discouraged in modern C++. In a function declaration, a **`void`** return value means that the function doesn't return a value; using it as a return type is a common and acceptable use of **`void`**. While the C language required functions that have zero parameters to declare **`void`** in the parameter list, for example, `fn(void)`, this practice is discouraged in modern C++; a parameterless function should be declared `fn()`. For more information, see [Type conversions and type safety](../cpp/type-conversions-and-type-safety-modern-cpp.md). -## const type qualifier +## `const` type qualifier -Any built-in or user-defined type may be qualified by the const keyword. Additionally, member functions may be **`const`**-qualified and even **`const`**-overloaded. The value of a **`const`** type cannot be modified after it is initialized. +Any built-in or user-defined type may be qualified by the **`const`** keyword. Additionally, member functions may be **`const`**-qualified and even **`const`**-overloaded. The value of a **`const`** type can't be modified after it's initialized. ```cpp const double PI = 3.1415; PI = .75; //Error. Cannot modify const variable. ``` -The **`const`** qualifier is used extensively in function and variable declarations and "const correctness" is an important concept in C++; essentially it means to use **`const`** to guarantee, at compile time, that values are not modified unintentionally. For more information, see [`const`](../cpp/const-cpp.md). +The **`const`** qualifier is used extensively in function and variable declarations and "const correctness" is an important concept in C++; essentially it means to use **`const`** to guarantee, at compile time, that values aren't modified unintentionally. For more information, see [`const`](../cpp/const-cpp.md). -A **`const`** type is distinct from its non-const version; for example, **`const int`** is a distinct type from **`int`**. You can use the C++ **`const_cast`** operator on those rare occasions when you must remove *const-ness* from a variable. For more information, see [Type Conversions and Type Safety](../cpp/type-conversions-and-type-safety-modern-cpp.md). +A **`const`** type is distinct from its non-**`const`** version; for example, **`const int`** is a distinct type from **`int`**. You can use the C++ **`const_cast`** operator on those rare occasions when you must remove *const-ness* from a variable. For more information, see [Type conversions and type safety](../cpp/type-conversions-and-type-safety-modern-cpp.md). ## String types -Strictly speaking, the C++ language has no built-in string type; **`char`** and **`wchar_t`** store single characters - you must declare an array of these types to approximate a string, adding a terminating null value (for example, ASCII `'\0'`) to the array element one past the last valid character (also called a *C-style string*). C-style strings required much more code to be written or the use of external string utility library functions. But in modern C++, we have the Standard Library types `std::string` (for 8-bit **`char`**-type character strings) or `std::wstring` (for 16-bit **`wchar_t`**-type character strings). These C++ Standard Library containers can be thought of as native string types because they are part of the standard libraries that are included in any conformant C++ build environment. Simply use the `#include ` directive to make these types available in your program. (If you are using MFC or ATL, the `CString` class is also available, but is not part of the C++ standard.) The use of null-terminated character arrays (the C-style strings previously mentioned) is strongly discouraged in modern C++. +Strictly speaking, the C++ language has no built-in string type; **`char`** and **`wchar_t`** store single characters - you must declare an array of these types to approximate a string, adding a terminating null value (for example, ASCII `'\0'`) to the array element one past the last valid character (also called a *C-style string*). C-style strings required much more code to be written or the use of external string utility library functions. But in modern C++, we have the Standard Library types `std::string` (for 8-bit **`char`**-type character strings) or `std::wstring` (for 16-bit **`wchar_t`**-type character strings). These C++ Standard Library containers can be thought of as native string types because they're part of the standard libraries that are included in any conformant C++ build environment. Use the `#include ` directive to make these types available in your program. (If you're using MFC or ATL, the `CString` class is also available, but isn't part of the C++ standard.) The use of null-terminated character arrays (the C-style strings previously mentioned) is discouraged in modern C++. ## User-defined types @@ -96,13 +100,15 @@ When you define a **`class`**, **`struct`**, **`union`**, or **`enum`**, that co - The compiler has no built-in knowledge of a user-defined type. It learns of the type when it first encounters the definition during the compilation process. -- You specify what operations can be performed on your type, and how it can be converted to other types, by defining (through overloading) the appropriate operators, either as class members or non-member functions. For more information, see [Function Overloading](function-overloading.md) +- You specify what operations can be performed on your type, and how it can be converted to other types, by defining (through overloading) the appropriate operators, either as class members or non-member functions. For more information, see [Function overloading](function-overloading.md) ## Pointer types -Dating back to the earliest versions of the C language, C++ continues to let you declare a variable of a pointer type by using the special declarator **`*`** (asterisk). A pointer type stores the address of the location in memory where the actual data value is stored. In modern C++, these are referred to as *raw pointers*, and are accessed in your code through special operators **`*`** (asterisk) or **`->`** (dash with greater-than). This is called *dereferencing*, and which one that you use depends on whether you are dereferencing a pointer to a scalar or a pointer to a member in an object. Working with pointer types has long been one of the most challenging and confusing aspects of C and C++ program development. This section outlines some facts and practices to help use raw pointers if you want to, but in modern C++ it's no longer required (or recommended) to use raw pointers for object ownership at all, due to the evolution of the [smart pointer](../cpp/smart-pointers-modern-cpp.md) (discussed more at the end of this section). It is still useful and safe to use raw pointers for observing objects, but if you must use them for object ownership, you should do so with caution and very careful consideration of how the objects owned by them are created and destroyed. +As in the earliest versions of the C language, C++ continues to let you declare a variable of a pointer type by using the special declarator **`*`** (asterisk). A pointer type stores the address of the location in memory where the actual data value is stored. In modern C++, these pointer types are referred to as *raw pointers*, and they're accessed in your code through special operators: **`*`** (asterisk) or **`->`** (dash with greater-than, often called *arrow*). This memory access operation is called *dereferencing*. Which operator you use depends on whether you're dereferencing a pointer to a scalar, or a pointer to a member in an object. + +Working with pointer types has long been one of the most challenging and confusing aspects of C and C++ program development. This section outlines some facts and practices to help use raw pointers if you want to. However, in modern C++, it's no longer required (or recommended) to use raw pointers for object ownership at all, due to the evolution of the [smart pointer](../cpp/smart-pointers-modern-cpp.md) (discussed more at the end of this section). It's still useful and safe to use raw pointers for observing objects. However, if you must use them for object ownership, you should do so with caution and with careful consideration of how the objects owned by them are created and destroyed. -The first thing that you should know is declaring a raw pointer variable will allocate only the memory that is required to store an address of the memory location that the pointer will be referring to when it is dereferenced. Allocation of the memory for the data value itself (also called *backing store*) is not yet allocated. In other words, by declaring a raw pointer variable, you are creating a memory address variable, not an actual data variable. Dereferencing a pointer variable before making sure that it contains a valid address to a backing store will cause undefined behavior (usually a fatal error) in your program. The following example demonstrates this kind of error: +The first thing that you should know is that a raw pointer variable declaration only allocates enough memory to store an address: the memory location that the pointer refers to when it's dereferenced. The pointer declaration doesn't allocate the memory needed to store the data value. (That memory is also called the *backing store*.) In other words, by declaring a raw pointer variable, you're creating a memory address variable, not an actual data variable. If you dereference a pointer variable before you've made sure that it contains a valid address for a backing store, it causes undefined behavior (usually a fatal error) in your program. The following example demonstrates this kind of error: ```cpp int* pNumber; // Declare a pointer-to-int variable. @@ -128,9 +134,9 @@ The example dereferences a pointer type without having any memory allocated to s // "pNumber". ``` -The corrected code example uses local stack memory to create the backing store that `pNumber` points to. We use a fundamental type for simplicity. In practice, the backing store for pointers are most often user-defined types that are dynamically-allocated in an area of memory called the *heap* (or *free store*) by using a **`new`** keyword expression (in C-style programming, the older `malloc()` C runtime library function was used). Once allocated, these variables are usually referred to as objects, especially if they are based on a class definition. Memory that is allocated with **`new`** must be deleted by a corresponding **`delete`** statement (or, if you used the `malloc()` function to allocate it, the C runtime function `free()`). +The corrected code example uses local stack memory to create the backing store that `pNumber` points to. We use a fundamental type for simplicity. In practice, the backing stores for pointers are most often user-defined types that are dynamically allocated in an area of memory called the *heap* (or *free store*) by using a **`new`** keyword expression (in C-style programming, the older `malloc()` C runtime library function was used). Once allocated, these variables are normally referred to as *objects*, especially if they're based on a class definition. Memory that is allocated with **`new`** must be deleted by a corresponding **`delete`** statement (or, if you used the `malloc()` function to allocate it, the C runtime function `free()`). -However, it is easy to forget to delete a dynamically-allocated object- especially in complex code, which causes a resource bug called a *memory leak*. For this reason, the use of raw pointers is strongly discouraged in modern C++. It is almost always better to wrap a raw pointer in a [smart pointer](../cpp/smart-pointers-modern-cpp.md), which will automatically release the memory when its destructor is invoked (when the code goes out of scope for the smart pointer); by using smart pointers you virtually eliminate a whole class of bugs in your C++ programs. In the following example, assume `MyClass` is a user-defined type that has a public method `DoSomeWork();` +However, it's easy to forget to delete a dynamically allocated object- especially in complex code, which causes a resource bug called a *memory leak*. For this reason, the use of raw pointers is discouraged in modern C++. It's almost always better to wrap a raw pointer in a [smart pointer](../cpp/smart-pointers-modern-cpp.md), which automatically releases the memory when its destructor is invoked. (That is, when the code goes out of scope for the smart pointer.) By using smart pointers, you virtually eliminate a whole class of bugs in your C++ programs. In the following example, assume `MyClass` is a user-defined type that has a public method `DoSomeWork();` ```cpp void someFunction() { @@ -141,28 +147,28 @@ void someFunction() { // for the unique_ptr, freeing the resource. ``` -For more information about smart pointers, see [Smart Pointers](../cpp/smart-pointers-modern-cpp.md). +For more information about smart pointers, see [Smart pointers](../cpp/smart-pointers-modern-cpp.md). -For more information about pointer conversions, see [Type Conversions and Type Safety](../cpp/type-conversions-and-type-safety-modern-cpp.md). +For more information about pointer conversions, see [Type conversions and type safety](../cpp/type-conversions-and-type-safety-modern-cpp.md). For more information about pointers in general, see [Pointers](../cpp/pointers-cpp.md). ## Windows data types -In classic Win32 programming for C and C++, most functions use Windows-specific typedefs and `#define` macros (defined in `windef.h`) to specify the types of parameters and return values. These Windows data types are mostly just special names (aliases) given to C/C++ built-in types. For a complete list of these typedefs and preprocessor definitions, see [Windows Data Types](/windows/win32/WinProg/windows-data-types). Some of these typedefs, such as `HRESULT` and `LCID`, are useful and descriptive. Others, such as `INT`, have no special meaning and are just aliases for fundamental C++ types. Other Windows data types have names that are retained from the days of C programming and 16-bit processors, and have no purpose or meaning on modern hardware or operating systems. There are also special data types associated with the Windows Runtime Library, listed as [Windows Runtime base data types](/windows/win32/WinRT/base-data-types). In modern C++, the general guideline is to prefer the C++ fundamental types unless the Windows type communicates some additional meaning about how the value is to be interpreted. +In classic Win32 programming for C and C++, most functions use Windows-specific typedefs and `#define` macros (defined in `windef.h`) to specify the types of parameters and return values. These Windows data types are mostly special names (aliases) given to C/C++ built-in types. For a complete list of these typedefs and preprocessor definitions, see [Windows Data Types](/windows/win32/WinProg/windows-data-types). Some of these typedefs, such as `HRESULT` and `LCID`, are useful and descriptive. Others, such as `INT`, have no special meaning and are just aliases for fundamental C++ types. Other Windows data types have names that are retained from the days of C programming and 16-bit processors, and have no purpose or meaning on modern hardware or operating systems. There are also special data types associated with the Windows Runtime Library, listed as [Windows Runtime base data types](/windows/win32/WinRT/base-data-types). In modern C++, the general guideline is to prefer the C++ fundamental types unless the Windows type communicates some extra meaning about how the value is to be interpreted. ## More information -For more information about the C++ type system, see the following topics. +For more information about the C++ type system, see the following articles. -[Value Types](../cpp/value-types-modern-cpp.md)\ +[Value types](../cpp/value-types-modern-cpp.md)\ Describes *value types* along with issues relating to their use. -[Type Conversions and Type Safety](../cpp/type-conversions-and-type-safety-modern-cpp.md)\ +[Type conversions and type safety](../cpp/type-conversions-and-type-safety-modern-cpp.md)\ Describes common type conversion issues and shows how to avoid them. ## See also -[Welcome back to C++](../cpp/welcome-back-to-cpp-modern-cpp.md)
-[C++ Language Reference](../cpp/cpp-language-reference.md)
+[Welcome back to C++](../cpp/welcome-back-to-cpp-modern-cpp.md)\ +[C++ language reference](../cpp/cpp-language-reference.md)\ [C++ Standard Library](../standard-library/cpp-standard-library-reference.md)