Refer to post #2:Originally Posted by SirPrattlepod
Refer to post #5:Originally Posted by Salem
Refer to post #8:Originally Posted by vart
And refer to std10093's post #15, with the caveat that the claim that "as a result, there is nothing there. So, sMain points to nothing" is inaccurate.Originally Posted by laserlight
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Code - functions and small libraries I use
It’s 2014 and I still use printf() for debugging.
"Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson
Code - functions and small libraries I use
It’s 2014 and I still use printf() for debugging.
"Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson
Strictly speaking, std10093, your description here is incorrect.
Accessing the value of an uninitialised variable yields undefined behaviour - it doesn't just retrieve an unknown value. And accessing the value of a variable is a logical precursor to adding a value to it.
Practically, what you say is often correct. I did actually encounter a small company who proudly demonstrated their proprietary in-house C compiler to me some years back. Among other things, when code was compiled for debugging, a runtime error would result whenever the value of an uninitialised basic variable (int, char, etc) was accessed. Having that happen when debugging, to say the least, gave a rather pointed object lesson related to uninitialised variables.
Usually we just say something like "therefore, the behaviour is undefined". The problem with claiming that there's "nothing there" is that the memory might still contain what was there, and then maybe, just maybe, that memory might be accessed without any apparent problem.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Both grumpy and laserlight are correct. Thank you both!
Code - functions and small libraries I use
It’s 2014 and I still use printf() for debugging.
"Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson
Indeed. I would argue that the nastiest (potential) result of undefined behaviour is what the programmer expects to happen. After all, if the programmer gets the result s/he expects, s/he might be deceived into believing the code is correct. This results in subtle bugs that are hard to find when porting code, updating compilers, patching compilers, changing optimisation settings, etc etc.