3 ms·
The debug builds in VC++ used to initialize memory with a certain pattern. That was pretty useful to see problems in the debugger. I think in general a defined
by maxxxxx 8y ago
The debug builds in VC++ used to initialize memory with a certain pattern. That was pretty useful to see problems in the debugger.
I think in general a defined default value is a good thing. Maybe it shouldn't be 0 but something like INT_MIN so you clearly see what something is wrong.
- loeg 8y ago0xdead for int16's and 0xdeadbeef for word+ values? :-D INT_MIN (0xffff) has a sort of collision with PCI MMIO read failures (timeouts, unsupported request, etc), which return all-bits-1.
- bsder 8y ago0xAA, 0xA5, 0x5A, 0x55 are generally good values. They tend to be low-probability values so if you get two of them together it's almost always a bug. They don't tend to collide with other things and are far enough away from overflow that they don't accidentally get masked by an off-by-one bug. They have interleaved 0's and 1's so that if you get a bit error, it sticks out. They're also obviously different enough that if they get copied, they kind of stick out. I tend to "initialize" my data to these by default. They also tend to be my go to for "deinitializing" data. It's remarkable how often I catch bugs in my C code simply by scanning RAM for those values.
- kazinator 8y agoThat approach is great for uninitialized pointers, but not so hot for numeric code.