Affected subclause: [conv.ptr]
Change: Converting
void* to a pointer-to-object type requires casting
.
char a[10];
void* b=a;
void foo() {
char* c=b;
}
ISO C will accept this usage of pointer to void being assigned
to a pointer to object type
. Rationale:
C++ tries harder than C to enforce compile-time type safety
. Effect on original feature:
Deletion of semantically well-defined feature
. Difficulty of converting:
Could be automated
. Violations will be diagnosed by the C++ translator
. The
fix is to add a cast
. For example:
char* c = (char*) b;
How widely used:
This is fairly widely used but it is good
programming practice to add the cast when assigning pointer-to-void to pointer-to-object
. Some ISO C translators will give a warning
if the cast is not used
.