Is it possible to cast struct to another?

后端 未结 4 535
名媛妹妹
名媛妹妹 2020-12-28 19:03

Any one could describe how (struct sockaddr *)&server works here? Is it possible to cast bigger struct to smaller struct?

See these structs:

4条回答
  •  时光说笑
    2020-12-28 19:56

    This is refered as Type Punning. Here, both structures have the same size, so there is no question of struct size. Although you can cast almost anything to anything, doing it with structures is error-prone.

提交回复
热议问题