12 ms·
This is dangerous of course because dogs are larger than cats, but I think he is correct. While every compiler I tried has this warning enabled for assignments
by raxxorrax 6y ago
This is dangerous of course because dogs are larger than cats, but I think he is correct. While every compiler I tried has this warning enabled for assignments or comparisons by default, I don't think the standard explicitly forbids it. Could be wrong though.
- hvdijk 6y ago> I don't think the standard explicitly forbids it. I already wrote exactly where the standard explicitly forbids it in the message you replied to.
- raxxorrax 6y agoI looked it up... > both operands are pointers to qualified or unqualified versions of compatible types Not sure, but I still would say he was correct. The compiler might not be able to check if the types are compatible, so the warning as a standard behavior is anticipatory. Sensible, yes.
- hvdijk 6y ago"Compatible type" is defined in the standard as well. It doesn't mean "whatever the compiler thinks is compatible", it's what the section "Compatible type and composite type" defines as compatible. Different struct types are not compatible.
- BunsanSpace 6y agoThe 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.