Fwd: strict aliasing and socket structures

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>How, exactly, did you discover this?  Do you know that the types
>are not compatible?  if so, please tell us precisely what the types
>are.

>Andrew.

You can try compiling any related code and it will give warnings like

" warning: dereferencing type-punned pointer might break strict-aliasing
rules"

Here's a snippet -

#include <iostream>
#include <cstring>
#include <netinet/in.h>

using namespace std;

int main(){

    sockaddr_storage addrStruct;
    memset(&addrStruct, 0, sizeof(addrStruct));

    sockaddr_in * tmp =
            reinterpret_cast<struct sockaddr_in *> (&addrStruct);
    tmp->sin_family = AF_INET;
}

It's in c++ but not too hard to imagine in C as well.
Here is online execution - http://melpon.org/wandbox/permlink/Y7IgD6Z8ha7VnvKA
Same warning as I said before.

You can try with any type you want, sockaddr_storage, _in, _in6,
_un etc and it shows these warnings. My original mail shows SO
links where I asked for these warnings and replies mentioned strict
alias violation.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux