Skip to content

Commit 5d6b8e2

Browse files
author
Colin Robertson
authored
Merge pull request MicrosoftDocs#59 from djeedai/master
Fix formatting of dllimport/dllexport page.
2 parents a3b0eb6 + c567227 commit 5d6b8e2

File tree

1 file changed

+55
-58
lines changed

1 file changed

+55
-58
lines changed

docs/cpp/definitions-and-declarations-cpp.md

Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -31,63 +31,60 @@ translation.priority.ht:
3131
- "zh-tw"
3232
---
3333
# Definitions and Declarations (C++)
34-
## Microsoft Specific
35-
The DLL interface refers to all items (functions and data) that are known to be exported by some program in the system; that is, all items that are declared as **dllimport** or `dllexport`. All declarations included in the DLL interface must specify either the **dllimport** or `dllexport` attribute. However, the definition must specify only the `dllexport` attribute. For example, the following function definition generates a compiler error:
36-
37-
```
38-
__declspec( dllimport ) int func() { // Error; dllimport
39-
// prohibited on definition.
34+
## Microsoft Specific
35+
The DLL interface refers to all items (functions and data) that are known to be exported by some program in the system; that is, all items that are declared as `dllimport` or `dllexport`. All declarations included in the DLL interface must specify either the `dllimport` or `dllexport` attribute. However, the definition must specify only the `dllexport` attribute. For example, the following function definition generates a compiler error:
36+
37+
```
38+
__declspec( dllimport ) int func() { // Error; dllimport
39+
// prohibited on definition.
4040
return 1;
41-
}
42-
```
43-
44-
This code also generates an error:
45-
46-
```
47-
#define DllImport __declspec( dllimport )
48-
49-
__declspec( dllimport ) int i = 10; // Error; this is a
50-
// definition.
51-
```
52-
53-
However, this is correct syntax:
54-
55-
```
56-
__declspec( dllexport ) int i = 10; // Okay--export definition
57-
```
58-
59-
The use of `dllexport` implies a definition, while **dllimport** implies a declaration. You must use the `extern` keyword with `dllexport` to force a declaration; otherwise, a definition is implied. Thus, the following examples are correct:
60-
61-
```
62-
#define DllImport __declspec( dllimport )
63-
#define DllExport __declspec( dllexport )
64-
65-
extern DllImport int k; // These are both correct and imply a
66-
DllImport int j; // declaration.
67-
```
68-
69-
The following examples clarify the preceding:
70-
71-
```
72-
static __declspec( dllimport ) int l; // Error; not declared extern.
73-
74-
void func() {
75-
static __declspec( dllimport ) int s; // Error; not declared
76-
// extern.
77-
__declspec( dllimport ) int m; // Okay; this is a
78-
// declaration.
79-
__declspec( dllexport ) int n; // Error; implies external
80-
// definition in local scope.
81-
extern __declspec( dllimport ) int i; // Okay; this is a
82-
// declaration.
83-
extern __declspec( dllexport ) int k; // Okay; extern implies
84-
// declaration.
85-
__declspec( dllexport ) int x = 5; // Error; implies external
86-
// definition in local scope.
87-
}
88-
```
89-
90-
**END Microsoft Specific**
91-
92-
## See Also
41+
}
42+
```
43+
44+
This code also generates an error:
45+
46+
```
47+
__declspec( dllimport ) int i = 10; // Error; this is a definition.
48+
```
49+
50+
However, this is correct syntax:
51+
52+
```
53+
__declspec( dllexport ) int i = 10; // Okay--export definition
54+
```
55+
56+
The use of `dllexport` implies a definition, while `dllimport` implies a declaration. You must use the `extern` keyword with `dllexport` to force a declaration; otherwise, a definition is implied. Thus, the following examples are correct:
57+
58+
```
59+
#define DllImport __declspec( dllimport )
60+
#define DllExport __declspec( dllexport )
61+
62+
extern DllImport int k; // These are both correct and imply a
63+
DllImport int j; // declaration.
64+
```
65+
66+
The following examples clarify the preceding:
67+
68+
```
69+
static __declspec( dllimport ) int l; // Error; not declared extern.
70+
71+
void func() {
72+
static __declspec( dllimport ) int s; // Error; not declared
73+
// extern.
74+
__declspec( dllimport ) int m; // Okay; this is a
75+
// declaration.
76+
__declspec( dllexport ) int n; // Error; implies external
77+
// definition in local scope.
78+
extern __declspec( dllimport ) int i; // Okay; this is a
79+
// declaration.
80+
extern __declspec( dllexport ) int k; // Okay; extern implies
81+
// declaration.
82+
__declspec( dllexport ) int x = 5; // Error; implies external
83+
// definition in local scope.
84+
}
85+
```
86+
87+
**END Microsoft Specific**
88+
89+
## See Also
9390
[dllexport, dllimport](../cpp/dllexport-dllimport.md)

0 commit comments

Comments
 (0)