Skip to content

Commit f19f02f

Browse files
authored
Merge pull request MicrosoftDocs#3219 from MicrosoftDocs/master
10/19/2020 AM Publish
2 parents ced5ff1 + 54b1f4e commit f19f02f

18 files changed

+282
-85
lines changed
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
title: "C/C++ projects and build systems in Visual Studio"
3-
ms.description: "Use Visual Studio to compile and build C++ projects for Windows, ARM or Linux based on any project system."
3+
description: "Use Visual Studio to compile and build C++ projects for Windows, ARM, or Linux based on any project system."
44
ms.date: "07/17/2019"
55
helpviewer_keywords: ["builds [C++]", "C++ projects, building", "projects [C++], building", "builds [C++], options", "C++, build options"]
66
ms.assetid: fa6ed4ff-334a-4d99-b5e2-a1f83d2b3008
77
ms.topic: "overview"
88
---
99
# C/C++ projects and build systems in Visual Studio
1010

11-
You can use Visual Studio to edit, compile and build any C++ code base with full IntelliSense support without having to convert that code into a Visual Studio project or compile with the MSVC toolset. For example, you can edit a cross-platform CMake project in Visual Studio on a Windows machine, then compile it for Linux using g++ on a remote Linux machine.
11+
You can use Visual Studio to edit, compile, and build any C++ code base with full IntelliSense support without having to convert that code into a Visual Studio project or compile with the MSVC toolset. For example, you can edit a cross-platform CMake project in Visual Studio on a Windows machine, then compile it for Linux using g++ on a remote Linux machine.
1212

1313
## C++ compilation
1414

@@ -22,25 +22,25 @@ Basic C++ compilation involves three main steps:
2222

2323
## The MSVC toolset
2424

25-
The Microsoft C++ compiler, linker, standard libraries, and related utilities comprise the MSVC compiler toolset (also called a toolchain or "build tools"). These are included in Visual Studio. You can also download and use the toolset as a standalone package for free from the [Build Tools for Visual Studio 2019 download location](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019).
25+
The Microsoft C++ compiler, linker, standard libraries, and related utilities make up the MSVC compiler toolset (also called a toolchain or "build tools"). These are included in Visual Studio. You can also download and use the toolset as a free standalone package from [Build Tools for Visual Studio 2019 download](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019).
2626

2727
You can build simple programs by invoking the MSVC compiler (cl.exe) directly from the command line. The following command accepts a single source code file, and invokes cl.exe to build an executable called *hello.exe*:
2828

2929
```cmd
3030
cl /EHsc hello.cpp
3131
```
3232

33-
Note that here the compiler (cl.exe) automatically invokes the C++ preprocessor and the linker to produce the final output file. For more information, see [Building on the command line](building-on-the-command-line.md).
33+
Here the compiler (cl.exe) automatically invokes the C++ preprocessor and the linker to produce the final output file. For more information, see [Building on the command line](building-on-the-command-line.md).
3434

3535
## Build systems and projects
3636

37-
Most real-world programs use some kind of *build system* to manage complexities of compiling multiple source files for multiple configurations (i.e. debug vs. release), multiple platforms (x86, x64, ARM, and so on), custom build steps, and even multiple executables that must be compiled in a certain order. You make settings in a build configuration file(s), and the build system accepts that file as input before it invoke the compiler. The set of source code files and build configuration files needed to build an executable file is called a *project*.
37+
Most real-world programs use some kind of *build system* to manage complexities of compiling multiple source files for multiple configurations (debug vs. release), multiple platforms (x86, x64, ARM, and so on), custom build steps, and even multiple executables that must be compiled in a certain order. You make settings in a build configuration file(s), and the build system accepts that file as input before it invoke the compiler. The set of source code files and build configuration files needed to build an executable file is called a *project*.
3838

3939
The following list shows various options for Visual Studio Projects - C++:
4040

4141
- create a Visual Studio project by using the Visual Studio IDE and configure it by using property pages. Visual Studio projects produce programs that run on Windows. For an overview, see [Compiling and Building](/visualstudio/ide/compiling-and-building-in-visual-studio) in the Visual Studio documentation.
4242

43-
- open a folder that contains a CMakeLists.txt file. CMake support is integrated into Visual Studio. You can use the IDE to edit, test and debug without modifying the CMake files in any way. This enables you to work in the same CMake project as others who might be using different editors. CMake is the recommended approach for cross-platform development. For more information, see [CMake projects](cmake-projects-in-visual-studio.md).
43+
- open a folder that contains a CMakeLists.txt file. CMake support is integrated into Visual Studio. You can use the IDE to edit, test, and debug without modifying the CMake files in any way. This enables you to work in the same CMake project as others who might be using different editors. CMake is the recommended approach for cross-platform development. For more information, see [CMake projects](cmake-projects-in-visual-studio.md).
4444

4545
- open a loose folder of source files with no project file. Visual Studio will use heuristics to build the files. This is an easy way to compile and run small console applications. For more information, see [Open Folder projects](open-folder-projects-cpp.md).
4646

@@ -50,45 +50,45 @@ The following list shows various options for Visual Studio Projects - C++:
5050

5151
## MSBuild from the command line
5252

53-
You can invoke MSBuild from the command line by passing it a .vcxproj file along with command-line options. This approach requires a good understanding of MSBuild, and is recommended only when absolutely necessary. For more information, see [MSBuild](msbuild-visual-cpp.md).
53+
You can invoke MSBuild from the command line by passing it a .vcxproj file along with command-line options. This approach requires a good understanding of MSBuild, and is recommended only when necessary. For more information, see [MSBuild](msbuild-visual-cpp.md).
5454

5555
## In This Section
5656

57-
[Visual Studio projects](creating-and-managing-visual-cpp-projects.md)
57+
[Visual Studio projects](creating-and-managing-visual-cpp-projects.md)\
5858
How to create, configure, and build C++ projects in Visual Studio using its native build system (MSBuild).
5959

60-
[CMake projects](cmake-projects-in-visual-studio.md)
60+
[CMake projects](cmake-projects-in-visual-studio.md)\
6161
How to code, build, and deploy CMake projects in Visual Studio.
6262

63-
[Open Folder projects](open-folder-projects-cpp.md)
64-
How to use Visual Studio to code, build and deploy C++ projects based on any arbitrary build system, or no build system. at all.
63+
[Open Folder projects](open-folder-projects-cpp.md)\
64+
How to use Visual Studio to code, build, and deploy C++ projects based on any arbitrary build system, or no build system at all.
6565

66-
[Release builds](release-builds.md)
66+
[Release builds](release-builds.md)\
6767
How to create and troubleshoot optimized release builds for deployment to end users.
6868

69-
[Use the MSVC toolset from the command line](building-on-the-command-line.md)<br/>
69+
[Use the MSVC toolset from the command line](building-on-the-command-line.md)\
7070
Discusses how to use the C/C++ compiler and build tools directly from the command line rather than using the Visual Studio IDE.
7171

72-
[Building DLLs in Visual Studio](dlls-in-visual-cpp.md)
73-
How to create, debug and deploy C/C++ DLLs (shared libraries) in Visual Studio.
72+
[Building DLLs in Visual Studio](dlls-in-visual-cpp.md)\
73+
How to create, debug, and deploy C/C++ DLLs (shared libraries) in Visual Studio.
7474

75-
[Walkthrough: Creating and Using a Static Library](walkthrough-creating-and-using-a-static-library-cpp.md)
76-
How to create a .lib binary file.
75+
[Walkthrough: Creating and Using a Static Library](walkthrough-creating-and-using-a-static-library-cpp.md)\
76+
How to create a **.lib** binary file.
7777

78-
[Building C/C++ Isolated Applications and Side-by-side Assemblies](building-c-cpp-isolated-applications-and-side-by-side-assemblies.md)
78+
[Building C/C++ Isolated Applications and Side-by-side Assemblies](building-c-cpp-isolated-applications-and-side-by-side-assemblies.md)\
7979
Describes the deployment model for Windows Desktop applications, based on the idea of isolated applications and side-by-side assemblies.
8080

81-
[Configure C++ projects for 64-bit, x64 targets](configuring-programs-for-64-bit-visual-cpp.md)
81+
[Configure C++ projects for 64-bit, x64 targets](configuring-programs-for-64-bit-visual-cpp.md)\
8282
How to target 64-bit x64 hardware with the MSVC build tools.
8383

84-
[Configure C++ projects for ARM processors](configuring-programs-for-arm-processors-visual-cpp.md)
84+
[Configure C++ projects for ARM processors](configuring-programs-for-arm-processors-visual-cpp.md)\
8585
How to use the MSVC build tools to target ARM hardware.
8686

87-
[Optimizing Your Code](optimizing-your-code.md)
87+
[Optimizing Your Code](optimizing-your-code.md)\
8888
How to optimize your code in various ways including program guided optimizations.
8989

90-
[Configuring Programs for Windows XP](configuring-programs-for-windows-xp.md)
90+
[Configuring Programs for Windows XP](configuring-programs-for-windows-xp.md)\
9191
How to target Windows XP with the MSVC build tools.
9292

93-
[C/C++ Building Reference](reference/c-cpp-building-reference.md)<br/>
93+
[C/C++ Building Reference](reference/c-cpp-building-reference.md)\
9494
Provides links to reference articles about program building in C++, compiler and linker options, and various build tools.

docs/c-language/c-keywords.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "C Keywords"
33
description: "Keywords in Standard C and Microsoft C compiler extensions."
4-
ms.date: 10/12/2020
4+
ms.date: 10/15/2020
55
helpviewer_keywords: ["keywords [C]", "redefining keywords", "Microsoft-specific keywords"]
66
ms.assetid: 2d932335-97bf-45cd-b367-4ae00db0ff42
77
---
@@ -121,7 +121,7 @@ The following keywords and special identifiers are recognized by the Microsoft C
121121

122122
<sup>5</sup> For compatibility with previous versions, these keywords are available both with two leading underscores and a single leading underscore when Microsoft extensions are enabled.
123123

124-
<sup>6</sup> When <assert.h> is not included, the Microsoft Visual C compiler maps **`static_assert`** to the C11 **`_Static_assert`** keyword.
124+
<sup>6</sup> If you don't include <assert.h>, the Microsoft Visual C compiler maps **`static_assert`** to the C11 **`_Static_assert`** keyword.
125125

126126
Microsoft extensions are enabled by default. To assist in creating portable code, you can disable Microsoft extensions by specifying the [/Za \(Disable language extensions)](../build/reference/za-ze-disable-language-extensions.md) option during compilation. When you use this option, some Microsoft-specific keywords are disabled.
127127

docs/c-language/noreturn.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: "_Noreturn keyword and noreturn macro (C11)"
3+
description: "Describes the `_Noreturn` keyword and `noreturn` macro."
4+
ms.date: 10/16/2020
5+
f1_keywords: ["_Noreturn_c", "noreturn"]
6+
helpviewer_keywords: ["keywords [C]"]
7+
---
8+
9+
# `_Noreturn` keyword and `noreturn` macro (C11)
10+
11+
The `_Noreturn` keyword was introduced in C11. It tells the compiler that the function it's applied to doesn't return. The compiler knows that the code following a call to a `_Noreturn` function is unreachable.
12+
13+
A convenience macro, `noreturn`, provided in <stdnoreturn.h>, maps to the `_Noreturn` keyword.
14+
15+
The primary benefits for using `_Noreturn` (or the equivalent `noreturn`) are making the intention of the function clear in the code for future readers, and detecting unintentionally unreachable code.
16+
17+
## Example using `noreturn` macro and `_Noreturn `keyword
18+
19+
The following example demonstrates the `_Noreturn` keyword and the equivalent `noreturn` macro.
20+
21+
IntelliSense may generate a spurious error, `E0065`, if you use the macro `noreturn` that you can ignore. It doesn't prevent you from running the sample.
22+
23+
```C
24+
// Compile with Warning Level4 (/W4) and /std:c11
25+
#include <stdio.h>
26+
#include <stdlib.h>
27+
#include <stdnoreturn.h>
28+
29+
noreturn void fatal_error(void)
30+
{
31+
exit(3);
32+
}
33+
34+
_Noreturn void not_coming_back(void)
35+
{
36+
puts("There's no coming back");
37+
fatal_error();
38+
return; // warning C4645 - function declared with noreturn has a return statement
39+
}
40+
41+
void done(void)
42+
{
43+
puts("We'll never get here");
44+
}
45+
46+
int main(void)
47+
{
48+
not_coming_back();
49+
done(); // warning c4702 - unreachable code
50+
51+
return 0;
52+
}
53+
```
54+
55+
## Requirements
56+
57+
|Macro|Required header|
58+
|-------------|---------------------|
59+
|**`noreturn`**|\<stdnoreturn.h>|
60+
61+
## See also
62+
63+
[/std (Specify language standard version)](../build/reference/std-specify-language-standard-version.md)\
64+
[/W4 (Specify warning level)](../build/reference/compiler-option-warning-level.md)
65+
[C4702 warning](../error-messages\compiler-warnings\compiler-warning-level-4-c4702.md)

docs/c-language/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@
434434
href: ../c-language/inline-functions.md
435435
- name: Inline assembler (C)
436436
href: ../c-language/inline-assembler-c.md
437+
- name: _Noreturn (C)
438+
href: ../c-language/noreturn.md
437439
- name: DLL import and export functions
438440
items:
439441
- name: DLL import and export functions
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: "Compiler Warning (level 4) C4388"
3+
description: "Microsoft C/C++ compiler warning C4388, its causes and resolution."
4+
ms.date: 10/16/2020
5+
f1_keywords: ["C4388"]
6+
helpviewer_keywords: ["C4388"]
7+
---
8+
# Compiler Warning (level 4) C4388
9+
10+
> '*token*' : signed/unsigned mismatch
11+
12+
Using the *token* operator to compare a **`signed`** and a larger **`unsigned`** number required the compiler to convert the **`signed`** value to the larger **`unsigned`** type.
13+
14+
## Remarks
15+
16+
One way to fix this warning is if you cast one of the two types when you compare **`signed`** and larger **`unsigned`** types.
17+
18+
This warning is off by default. You can use [/Wall](../../build/reference/compiler-option-warning-level.md) or **`/w44388`** to enable it on the command line as a level 4 warning. Or, use [`#pragma warning(default:4388)`](../../preprocessor/warning.md) in your source file. For more information, see [Compiler warnings that are off by default](../../preprocessor/compiler-warnings-that-are-off-by-default.md).
19+
20+
## Example
21+
22+
This sample generates C4388 and shows how to fix it:
23+
24+
```cpp
25+
// C4388.cpp
26+
// compile with: cl /EHsc /W4 C4388.cpp
27+
#pragma warning(default: 4388)
28+
29+
int main() {
30+
unsigned long long uc = 0;
31+
int c = 0;
32+
unsigned long long c2 = c; // implicit conversion
33+
34+
if (uc < c) // C4388
35+
uc = 0;
36+
37+
if (uc < (unsigned long long)(c)) // OK
38+
uc = 0;
39+
40+
if (uc < c2) // Also OK
41+
uc = 0;
42+
}
43+
```
44+
45+
## See also
46+
47+
[Compiler Warning (Level 3) C4018](compiler-warning-level-3-c4018.md)\
48+
[Compiler Warning (Level 4) C4389](compiler-warning-level-4-c4389.md)
Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,44 @@
11
---
22
title: "Compiler Warning (level 3) C4018"
3-
ms.date: "11/04/2016"
3+
description: "Microsoft C/C++ compiler warning C4018, its causes and resolution."
4+
ms.date: 10/16/2020
45
f1_keywords: ["C4018"]
56
helpviewer_keywords: ["C4018"]
6-
ms.assetid: 6e8cbb04-d914-4319-b431-cbc2fbe40eb1
77
---
88
# Compiler Warning (level 3) C4018
99

10-
'expression' : signed/unsigned mismatch
10+
> '*token*' : signed/unsigned mismatch
1111
12-
Comparing a signed and unsigned number required the compiler to convert the signed value to unsigned.
12+
Using the *token* operator to compare **`signed`** and **`unsigned`** numbers required the compiler to convert the **`signed`** value to **`unsigned`**.
1313

14-
This warning may be fixed if you cast one of the two types when testing signed and unsigned types.
14+
## Remarks
1515

16-
The following sample generates C4018:
16+
One way to fix this warning is if you cast one of the two types when you compare **`signed`** and **`unsigned`** types.
17+
18+
## Example
19+
20+
This sample generates C4018 and shows how to fix it:
1721

1822
```cpp
1923
// C4018.cpp
20-
// compile with: /W3
24+
// compile with: cl /EHsc /W4 C4018.cpp
2125
int main() {
22-
unsigned int uc = 0;
23-
int c = 0;
24-
unsigned int c2 = 0;
26+
unsigned int uc = 0;
27+
int c = 0;
28+
unsigned int c2 = c; // implicit conversion
29+
30+
if (uc < c) // C4018
31+
uc = 0;
2532

26-
if (uc < c) uc = 0; // C4018
33+
if (uc < unsigned(c)) // OK
34+
uc = 0;
2735

28-
// OK
29-
if (uc == c2) uc = 0;
36+
if (uc < c2) // Also OK
37+
uc = 0;
3038
}
3139
```
40+
41+
## See also
42+
43+
[Compiler Warning (Level 4) C4388](c4388.md)\
44+
[Compiler Warning (Level 4) C4389](compiler-warning-level-4-c4389.md)
Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,49 @@
11
---
22
title: "Compiler Warning (level 4) C4389"
3-
ms.date: "11/04/2016"
3+
description: "Microsoft C/C++ compiler warning C4389, its causes and resolution."
4+
ms.date: 10/16/2020
45
f1_keywords: ["c4389"]
56
helpviewer_keywords: ["C4389"]
6-
ms.assetid: fc0e3a8e-f766-437c-b7f1-e61abb2a8765
77
---
88
# Compiler Warning (level 4) C4389
99

10-
'operator' : signed/unsigned mismatch
10+
> '*equality-operator*' : signed/unsigned mismatch
1111
12-
An operation involved signed and unsigned variables. This could result in a loss of data.
12+
An **`==`** or **`!=`** operation involved **`signed`** and **`unsigned`** variables. This could result in a loss of data.
13+
14+
## Remarks
15+
16+
One way to fix this warning is if you cast one of the two types when you compare **`signed`** and **`unsigned`** types.
17+
18+
## Example
1319

1420
The following sample generates C4389:
1521

1622
```cpp
1723
// C4389.cpp
18-
// compile with: /W4
19-
#pragma warning(default: 4389)
24+
// compile with: cl /EHsc /W4 C4389.cpp
2025

2126
int main()
2227
{
2328
int a = 9;
2429
unsigned int b = 10;
30+
int result = 0;
31+
2532
if (a == b) // C4389
26-
return 0;
33+
result = 1;
2734
else
28-
return 0;
29-
};
35+
result = 2;
36+
37+
if (unsigned(a) == b) // OK
38+
result = 3;
39+
else
40+
result = 4;
41+
42+
return result;
43+
}
3044
```
45+
46+
## See also
47+
48+
[Compiler Warning C4018](compiler-warning-level-3-c4018.md)\
49+
[Compiler Warning (Level 4) C4388](c4388.md)

0 commit comments

Comments
 (0)