What are the dangers of uninitialised variables?

前端 未结 4 1524
-上瘾入骨i
-上瘾入骨i 2021-01-18 20:38

In a program I am writing I currently have several uninitialised variables in my .h files, all of which are initialised at run-time. However, in Visual Studio it warns me ev

4条回答
  •  长发绾君心
    2021-01-18 21:13

    It's a safety measure to not allow uninitialized variables, witch is a good thing, but if you are sure of what you are doing and you make sure your variables are always initialzed before use, you can turn this off, right click on your project in solution explorer -> properties -> C/C++ -> SDL checks, this should be marked as NO. It comes as YES by default.

    Note that these compile-time checks do more than just check for unitialized variables, so before you turn this off I advise reading https://docs.microsoft.com/en-us/cpp/build/reference/sdl-enable-additional-security-checks?view=vs-2019

    You can also disable a specific warning in you code using warning pragma

    Personally I keep these on because IMO in the tradeoff safety/annoyance I prefer safety, but I reckon that someone else can have a different opinion.

提交回复
热议问题