{"id":961,"date":"2022-08-30T15:10:04","date_gmt":"2022-08-30T15:10:04","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/dereferencing-type-punned-pointer-will-break-strict-aliasing-rules-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:10:04","modified_gmt":"2022-08-30T15:10:04","slug":"dereferencing-type-punned-pointer-will-break-strict-aliasing-rules-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/dereferencing-type-punned-pointer-will-break-strict-aliasing-rules-collection-of-common-programming-errors\/","title":{"rendered":"Dereferencing type-punned pointer will break strict-aliasing rules-Collection of common programming errors"},"content":{"rendered":"<p>It looks a lot as if you really want to use fread:<\/p>\n<pre><code>int data;\nfread(&amp;data, sizeof(data), 1, stream);\n<\/code><\/pre>\n<p>That said, if you do want to go the route of reading chars, then reinterpreting them as an int, the safe way to do it is to use a union:<\/p>\n<pre><code>union\n{\n    char theChars[4];\n    int theInt;\n} myunion;\n\nfor(int i=0; i<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:07:36. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>It looks a lot as if you really want to use fread: int data; fread(&amp;data, sizeof(data), 1, stream); That said, if you do want to go the route of reading chars, then reinterpreting them as an int, the safe way to do it is to use a union: union { char theChars[4]; int theInt; } [&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-961","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/961","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=961"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/961\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}