Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Berkley Sockets, breaking aliasing rules?

Im asking my self, can i use the BSD sockets with strict aliasing on, without getting undefined behaviour by compiling with gcc?

bind(sdListen, (struct sockaddr*)&sockaddr_inIdentifier, sizeof(sockaddr_inIdentifier))

This line of code breaks the strict aliasing rule as far as i know (and gcc gives me the same warning). so is there a plan b, of using the sockets in O3 mode without turning strictaliasing of? And of course without breaking the rule? or do i have to get an own socket system running that will be runnable on all systems/compilers?

like image 403
dhein Avatar asked Aug 01 '13 08:08

dhein


1 Answers

The cast itself in that line does not break the strict aliasing rule. The rule is only broken if the implementation of bind() dereferences that pointer without converting it back to the right type.

Any strict aliasing problems there are problems for the implementer of bind(), not the user.

like image 192
caf Avatar answered Nov 20 '22 04:11

caf