{"id":605,"date":"2022-08-30T15:04:08","date_gmt":"2022-08-30T15:04:08","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/bit-shift-compiler-bug-or-a-corner-case-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:04:08","modified_gmt":"2022-08-30T15:04:08","slug":"bit-shift-compiler-bug-or-a-corner-case-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/bit-shift-compiler-bug-or-a-corner-case-collection-of-common-programming-errors\/","title":{"rendered":"Bit shift compiler bug or a corner case?-Collection of common programming errors"},"content":{"rendered":"<p>The following code outputs 0,1,32,33. Which is counter intuitive to say the least. But if I replace the literal 1 with the type annonated constant &#8220;ONE&#8221;, the loop runs fine.<\/p>\n<p>This is with gcc 4.6.2 and -std=c++0x.<\/p>\n<pre><code>#include\n#include\nusing namespace std;\nint main()\n    {\n    int64_t bitmask = 3;\n    int64_t k;\n    const int64_t ONE = 1;\n    cout<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-09 21:07:19. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>The following code outputs 0,1,32,33. Which is counter intuitive to say the least. But if I replace the literal 1 with the type annonated constant &#8220;ONE&#8221;, the loop runs fine. This is with gcc 4.6.2 and -std=c++0x. #include #include using namespace std; int main() { int64_t bitmask = 3; int64_t k; const int64_t ONE = [&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-605","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/605","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=605"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/605\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}