I Do Not Know C: Short quiz on undefined behavior (2015)
1–10 of 189 posts
Re: I Do Not Know C: Short quiz on undefined behavior (2015)
#2Re: I Do Not Know C: Short quiz on undefined behavior (2015)
#3Related reading:
http://blog.metaobject.com/2014/04/cc-osmartass.html
http://blog.regehr.org/archives/1180 and https://news.ycombinator.com/item?id=8233484
Re: I Do Not Know C: Short quiz on undefined behavior (2015)
#4Re: I Do Not Know C: Short quiz on undefined behavior (2015)
#5Re: I Do Not Know C: Short quiz on undefined behavior (2015)
#61. Unless C's variable definition rules are completely different from C++'s, int i; is a full definition, not a declaration. If both definitions appear at the same scope (e.g. global), this will cause either a compiler error or a linker error. A variable declaration would be extern int i;
Re: I Do Not Know C: Short quiz on undefined behavior (2015)
#7IMHO the problem is with compilers (and their developers) who think UB really means they can do anything , when what programmers usually expect is, and the standard even notes for one of the possible interpretations of UB, "behaving during translation or program execution in a documented manner characteristic of the environment". Related reading: http://blog.metaobject.com/2014/04/cc-osmartass.html http://blog.regehr…
if(undefined_behavior) {
ruin_developers_day();
}
It tends to be the effects of valid by the spec optimizations making assumptions that would only not be true during undefined behavior.Re: I Do Not Know C: Short quiz on undefined behavior (2015)
#8Re: I Do Not Know C: Short quiz on undefined behavior (2015)
#91. Unless C's variable definition rules are completely different from C++'s, int i; is a full definition, not a declaration. If both definitions appear at the same scope (e.g. global), this will cause either a compiler error or a linker error. A variable declaration would be extern int i;
C's variable definition rules are different from C++'s. gcc happily compiles those two lines, g++ exits with the "redefinition" error.