|
|
|
|
|
by akvadrako
3547 days ago
|
|
Yes, you are right, void * is an exception. However, any other pointer cannot be reliably casted: From C1X, section 6.3.2.3: "A pointer to an object type may be converted to a pointer to a different object type. If the
resulting pointer is not correctly aligned for the referenced type, the behavior is
undefined." Though that is quite odd, since any pointer can be converted to void* , which only needs alignment to the char type. So converting from x* -> y* is undefined, but x* -> void* -> y* is defined. |
|
>> uint8_t x[100];
>> uint32_t *y = &x[1];
And then dereference y, most RISC architectures will trap on the unaligned access. It doesn't matter if there is an intermediate void pointer or not.