4 ms·
In C, int I = 0; can be an uninitialized variable
- quelsolaar 4y agogoto jumpover; int i = 0; jumpover : printf("%i", i); /* i is defined but uninitialized. */
- DougMerritt 4y agoYep, that seems to be simpler but equivalent. A comment there said they don't see the problem (presumably due to the all-too-common "screw the human, git gud" attitude in the face of Undefined Behavior). And I further presume that the most defensible answer is that the problem is that asking the compiler for a warning on uninitialized variable use fails in this case. As an aside on the presumed language/standards-lawyering, as a compiler writer, I personally think that compilers should try their best to help the user, far more than trying to take the side of the language standard in a user-hostile way, but that's just me.
- kstenerud 4y agoNo, it can't. His example doesn't even contain "int i = 0". He has "int i;" followed later by an initializer that can be skipped depending on the rather funky switch logic he's added (i.e. it's undefined behavior). Nothing to see here. Clickbait title.
- quelsolaar 4y agoMaybe other readers will be able to see that the example includes many different tests when things are declared and not initialized. The goto example specifically contains int i = 0, but users are less likely to run in to that one since it is goto. Using an uninitialized variable is Undefined behaviour. Thats the point.