{"id":628,"date":"2022-08-30T15:04:31","date_gmt":"2022-08-30T15:04:31","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/scope-of-variably-sized-array-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:04:31","modified_gmt":"2022-08-30T15:04:31","slug":"scope-of-variably-sized-array-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/scope-of-variably-sized-array-collection-of-common-programming-errors\/","title":{"rendered":"Scope of variably sized array-Collection of common programming errors"},"content":{"rendered":"<p>No, for two separate reasons:<\/p>\n<p><em>C++:<\/em> The code isn&#8217;t valid C++. Arrays in C++ must have a compile-time constant size.<\/p>\n<p><em>C:<\/em> No, because the array only lives until the end of the block in which it was declared, and thus dereferencing <code>x<\/code> is undefined behaviour.<\/p>\n<p>From C11, 6.2.4\/2:<\/p>\n<blockquote>\n<p>If an object is referred to outside of its lifetime, the behavior is undefined.<\/p>\n<\/blockquote>\n<p>And 6.2.4\/7 says that the variable-length array lives from its declaration until the end of its enclosing scope:<\/p>\n<blockquote>\n<p>For such an object that does have a variable length array type, its lifetime extends from the declaration of the object until execution of the program leaves the scope of the declaration.<\/p>\n<\/blockquote>\n<p id=\"rop\"><small>Originally posted 2013-11-09 21:08:52. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>No, for two separate reasons: C++: The code isn&#8217;t valid C++. Arrays in C++ must have a compile-time constant size. C: No, because the array only lives until the end of the block in which it was declared, and thus dereferencing x is undefined behaviour. From C11, 6.2.4\/2: If an object is referred to outside [&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-628","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/628","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=628"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/628\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}