I came across a socket programming tutorial in which it is quoted
\"a pointer to a struct sockaddr_in can be cast to a pointer to a struct sockad
I'll add to @gsamaras answer by saying that Undefined Behaviour doesn't always means that bad things are about to happen. Undefined Behaviour actually says "we* don't provide any specifications on what should happen next if XYZ occurs".
(*the C++ standard).
this is the place where the OS takes place and say "it is defined by us".
although casting unrelated structs (sockaddr_in
,sockaddr
) may be undefined behaviour by the standard, the OS API specify that it is valid with their API.