Uninitialised variable
Jun. 6th, 2016 12:57 pmIn C and C++, you should avoid using an uninitialised variable for several reasons, not least of which, it's undefined behaviour (?) But in practice, what are the relative likelihoods of the (I think?) permitted outcomes:
(a) it being treated as some unknown value
(b) the following code being deleted by the compiler
(c) something even weirder happening?
(a) it being treated as some unknown value
(b) the following code being deleted by the compiler
(c) something even weirder happening?
no subject
Date: 2016-06-06 01:30 pm (UTC)I could be totally wrong about all of this, though.
no subject
Date: 2016-06-06 04:29 pm (UTC)But there's a smaller set of cases where the value is (eg) incremented but not used. And you shouldn't do that, partly because it will be misleading, and partly because even if it doesn't produce weird behaviour now, it might in future with some other compiler version. But if your code is full of other bad things that don't produce bugs right now, I don't know if this one is in the "don't even allow the program to run with this in" category or the "if it seems to work, there's no point singling it out" category.