jack: (Default)
[personal profile] jack
In 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?

Date: 2016-06-06 04:55 pm (UTC)
gerald_duck: (duck and computer)
From: [personal profile] gerald_duck
What's most likely is that you'll get undefined behaviour. That's not the same thing as an undefined value, so straddles the line between your options a and c.

For example, if I write: char c; int i = c; f(i); it's entirely possible for f to be passed 227316459 as its argument, even though that's not a value a char can have. Leaving aside that the compiler would complain bitterly about a case that artificial and obvious, then applying option b.