{"id":566,"date":"2022-08-30T15:03:29","date_gmt":"2022-08-30T15:03:29","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/function-with-missing-return-value-behavior-at-runtime-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:03:29","modified_gmt":"2022-08-30T15:03:29","slug":"function-with-missing-return-value-behavior-at-runtime-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/function-with-missing-return-value-behavior-at-runtime-collection-of-common-programming-errors\/","title":{"rendered":"Function with missing return value, behavior at runtime-Collection of common programming errors"},"content":{"rendered":"<p>As expected, the compiler (VisualStudio 2008) will give a warning<\/p>\n<blockquote>\n<p>warning C4715: &#8216;doSomethingWith&#8217; : not all control paths return a value<\/p>\n<\/blockquote>\n<p>when compiling the following code:<\/p>\n<pre><code>int doSomethingWith(int value)\n{\n    int returnValue = 3;\n    bool condition = false;\n\n    if(condition)\n        \/\/ returnValue += value; \/\/ DOH\n\n    return returnValue;\n}\n\nint main(int argc, char* argv[])\n{\n    int foo = 10;\n    int result = doSomethingWith(foo);\n    return 0;\n}\n<\/code><\/pre>\n<p>But the program runs just fine. The return value of function doSomethingWith() is 0.<\/p>\n<p>Is is just undefined behavior, or is there a certain rule how the result value is created\/computed at runtime. What happens with non-POD datatypes as return value?<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 20:53:37. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>As expected, the compiler (VisualStudio 2008) will give a warning warning C4715: &#8216;doSomethingWith&#8217; : not all control paths return a value when compiling the following code: int doSomethingWith(int value) { int returnValue = 3; bool condition = false; if(condition) \/\/ returnValue += value; \/\/ DOH return returnValue; } int main(int argc, char* argv[]) { int [&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-566","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/566","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=566"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/566\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}