Safe reinterpret_cast with sockaddr?
Assume I'm doing some socket programming: struct sockaddr_in sa; inet_pton(AF_INET, "127.0.0.1", &(sa.sin_addr)); auto *resa = reinterpret_cast<struct sockaddr*>(&sa); bind(sfd, resa, sizeof(sa)); Now the question is: we do reinterpret_cast (or C-style (struct sockaddr *) cast like in tutorials or man) yet the standard does not guarantee that to work, right? On the other hand there does not seem to be a way to do that differently, bind() requires struct sockaddr* (and it has to access the underlying struct to determine what it received). So is it safe to do reinterpret_cast between different t
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.