3 ms·
The standard does not. It's common to get a data payload of struct A, but cast it's pointer to struct B which is a subset of struct A (at is the first elements
by BunsanSpace 6y ago
The standard does not.
It's common to get a data payload of struct A, but cast it's pointer to struct B which is a subset of struct A (at is the first elements.
Actually in the Win32 API this is done a lot. Often you're even given a void* to some arbitrary data that you need to figure out what should be there. Sometimes it's not even a pointer it's two integers packed together, in the case of WM_MOUSEMOVE messages.
- richardwhiuk 6y agoA* -> void* -> A* is legal A* -> void* -> B* is undefined A* -> B* is undefined If you want to get the first element, you want, &(A->first), not a cast. The cast isn't guaranteed to be defined, and isn't guaranteed to be the same.