I've got code that looks something like this, where addr is a sockaddr*:
struct sockaddr_in *sin = (struct sockaddr_in *) addr;
const char *IP=inet_ntoa(sin -> sin_addr);
I believe this is very typical code for using Berkeley sockets.
However, when I compile this, I'm getting the following warning:
dereferencing pointer 'sin' does break strict anti-aliasing rules
Searching online, I find some discussion of the fact that the way I'm doing things is pretty typical, but this compiler warning also is pretty real and not a good thing.
What's the proper way to redo this code to fix the warning, and not just silence it?
I had the same issue - it looks like a bug in gcc.
I was able to get around it by using
(*sin).sin_addr
instead of
sin->sin_addr