casting between sockaddr and sockaddr_in

后端 未结 3 2062
独厮守ぢ
独厮守ぢ 2021-01-13 13:02

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

3条回答
  •  無奈伤痛
    2021-01-13 13:19

    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.

提交回复
热议问题