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 01:30 pm (UTC)
seekingferret: Two warning signs one above the other. 1) Falling Rocks. 2) Falling Rocs. (Default)
From: [personal profile] seekingferret
I'm not much of a programmer, but my understanding was that (a) was the primary concern, that as C/C++ does not require its compilers to check whether a variable is initialized, the variable will have the value of whatever its memory location previously had, and this can obviously have all sorts of unexpected results. But obviously some C compilers DO check if variables are initialized, despite it not being required (I think?) so I guess (b) and (c) are possible as well as (d)the compiler refuses to compile until you override or fix the problem.

I could be totally wrong about all of this, though.