{"id":946,"date":"2022-08-30T15:09:49","date_gmt":"2022-08-30T15:09:49","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/berkley-sockets-breaking-aliasing-rules-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:09:49","modified_gmt":"2022-08-30T15:09:49","slug":"berkley-sockets-breaking-aliasing-rules-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/berkley-sockets-breaking-aliasing-rules-collection-of-common-programming-errors\/","title":{"rendered":"Berkley Sockets, breaking aliasing rules?-Collection of common programming errors"},"content":{"rendered":"<p>Im asking my self, can i use the BSD sockets with strict aliasing on, without getting undefined behaviour by compiling with gcc?<\/p>\n<pre><code>bind(sdListen, (struct sockaddr*)&amp;sockaddr_inIdentifier, sizeof(sockaddr_inIdentifier))\n<\/code><\/pre>\n<p>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?<\/p>\n<ol>\n<li>\n<p>The cast itself in that line does not break the strict aliasing rule. The rule is only broken if the implementation of <code>bind()<\/code> dereferences that pointer without converting it back to the right type.<\/p>\n<p>Any strict aliasing problems there are problems for the implementer of <code>bind()<\/code>, not the user.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:05:11. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>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*)&amp;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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-946","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/946","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=946"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/946\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=946"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}