Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dereferencing pointer does break strict anti-aliasing rules using Berkeley sockets

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?

like image 436
Nantucket Avatar asked Aug 12 '10 05:08

Nantucket


1 Answers

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
like image 149
tloach Avatar answered Sep 20 '22 05:09

tloach