tmp/tmp6kazjf9d/{from.md → to.md}
RENAMED
|
@@ -1,28 +0,0 @@
|
|
| 1 |
-
### Clause [[conv]]: standard conversions <a id="diff.conv">[[diff.conv]]</a>
|
| 2 |
-
|
| 3 |
-
[[conv.ptr]] **Change:** Converting `void*` to a pointer-to-object type
|
| 4 |
-
requires casting.
|
| 5 |
-
|
| 6 |
-
``` cpp
|
| 7 |
-
char a[10];
|
| 8 |
-
void* b=a;
|
| 9 |
-
void foo() {
|
| 10 |
-
char* c=b;
|
| 11 |
-
}
|
| 12 |
-
```
|
| 13 |
-
|
| 14 |
-
ISO C will accept this usage of pointer to void being assigned to a
|
| 15 |
-
pointer to object type. C++will not. **Rationale:** C++tries harder than
|
| 16 |
-
C to enforce compile-time type safety. **Effect on original feature:**
|
| 17 |
-
Deletion of semantically well-defined feature. Could be automated.
|
| 18 |
-
Violations will be diagnosed by the C++translator. The fix is to add a
|
| 19 |
-
cast. For example:
|
| 20 |
-
|
| 21 |
-
``` cpp
|
| 22 |
-
char* c = (char*) b;
|
| 23 |
-
```
|
| 24 |
-
|
| 25 |
-
This is fairly widely used but it is good programming practice to add
|
| 26 |
-
the cast when assigning pointer-to-void to pointer-to-object. Some ISO C
|
| 27 |
-
translators will give a warning if the cast is not used.
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|