Should Local Variable Initialisation Be Mandatory?

前端 未结 17 2495
忘掉有多难
忘掉有多难 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:11

    Sometimes you need a variable as a placeholder (e.g. using the ftime functions), so it doesn't make sense to initialize them before calling the initialization function.

    However it wouldn't be bad, in my opinion, to annotate the fact that you are aware of the pitfalls, something in the way of

    uninitialized time_t t;
    time( &t );
    

提交回复
热议问题