Uninitialized memory blocks in VC++

前端 未结 15 1291
鱼传尺愫
鱼传尺愫 2020-12-19 08:49

As everyone knows, the Visual C++ runtime marks uninitialized or just freed memory blocks with special non-zero markers. Is there any way to disable this behavior entirely w

15条回答
  •  死守一世寂寞
    2020-12-19 09:08

    I'm pretty sure you can't disable the visual studio default here, and even if you did, the value would then be just whatever was in memory before the memory was allocated.

    Your best off just getting in the habit of setting them to 0 in the first place, it's only 2 extra charecters.

    int *ptr=0;
    

    You can also use the NULL macro, which is defined as 0 (but not be default, so be carful with multiple definitions when includeing stuff like windows.h and defining it yourself!

提交回复
热议问题