4 ms·
> C and C++ do not require variables to be initialized on declaration (explicitly or implicitly) like Go and Java. Reading from an uninitialized variable is und
by aatd86 3y ago
> C and C++ do not require variables to be initialized on declaration (explicitly or implicitly) like Go and Java. Reading from an uninitialized variable is undefined behavior.
Took me some time to understand that part :)
I always thought that an unassigned variable of type slice T was deemed uninitialized. (but then, what of assigning nil to a previously non-nil variable? Is it considered deinitialized?)
In fact, at the language level it could be considered uninitialized/deinitialized.
That's the variable typestate.
(cf definite assignment, ineffectual assignment analysis)
For the compiler, it still "points" to a memory location so it is initialized.
Am I right? (more than 344 comments, no one will find this one question lol :-)