I\'m writing with visual c++ and when I compile this error occures:
C:\\Program Files (x86)\\MSBuild\\Microsoft.Cpp\\v4.0\\Platforms\\Win32\\Microsoft.Cpp.Wi
Just wanted to add another case where this happens with Visual C++ 2019 (16.1.4):
...
char *s;
for(int i = 0; i < n; ++i)
{
if(i == 4) // we know n is going to be >= 4 but Visual C++ doesn't
s = getStringPointerFromSomewhere();
}
puts(s);
Visual C++ will print a message in the Output: potentially uninitialized local pointer variable 's' used, but crash instead of reporting it as a normal error or warning (arguably this should be a warning, since it's perfectly legal C code).
The solution for this one is to just assign s to NULL after declared:
char *s = NULL;
(So... just use the probably good habit of initializing pointers and other variables when declared I guess.)