Should Local Variable Initialisation Be Mandatory?

前端 未结 17 2975
忘掉有多难
忘掉有多难 2021-02-14 01:26

The maintenance problems that uninitialised locals cause (particularly pointers) will be obvious to anyone who has done a bit of c/c++ maintenance or enhancement, but I still se

17条回答
  •  爱一瞬间的悲伤
    2021-02-14 02:18

    As a simple example, can you determine what this will be initialised to (C/C++)?

    bool myVar;
    

    We had an issue in a product that would sometimes draw an image on screen and sometimes not, usually depending on who's machine it was built with. It turned out that on my machine it was being initialised to false, and on a colleagues machine it was being initialised to true.

提交回复
热议问题