cast operator
Performs explicit type conversion
# Notes
Because const, volatile, restrict, and _Atomic qualifiers have effect on lvalues only, a cast to a cvr-qualified or atomic type is exactly equivalent to the cast to the corresponding unqualified type.
The cast to void is sometimes useful to silence compiler warnings about unused results.
The conversions not listed here are not allowed. In particular,
If the implementation provides intptr_t and/or uintptr_t, then a cast from a pointer to an object type (including cv void) to these types is always well-defined. However, this is not guaranteed for a function pointer.
Note that conversions between function pointers and object pointers are accepted as extensions by many compilers, and expected by some usages of POSIX dlsym() function.
# Example
#include <stdio.h>
int main(void)
{
// examining object representation is a legitimate use of cast
double d = 3.14;
printf("The double %.2f (%a) is: ", d, d);
for (size_t n = 0; n < sizeof d; ++n)
printf("0x%02x ", ((unsigned char*)&d)[n]);
// edge cases
struct S { int x; } s;
// (struct S)s; // error; not a scalar type
// even though casting to the same type does nothing
(void)s; // okay to cast any type to void
}