Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- You declare:
- double d;
- In memory :-
- Address: 1234-00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
- Data: CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC
- ^
- |
- d points to here
- A double, on a PC, in 32bit Windows, normally, is 8 bytes long
- In debug mode, the memory is initialised to CC, both for the memory for the double, and immediately before and after.
- When d goes out of scope (at the end of your function), _in debug mode_, a check is made on the memory immediately before and after (so addresses 00 and 01, and 0A and 0B - not sure exactly how many bytes are checked, could be more, could be less), that they still contain CC.
- If they don't, then you've been bad and written over memory you weren't supposed to.
- Like
- *(&d - 1) = 0;
- Whoops, you've just written over the 8 bytes _before_ those you were allocated. In release mode, it might work, it might wipe your files or kill your dog. In debug mode (at least with Visual C++), it will notice and warn you.
- So, why is -9.2559631349317831e+061 the magic number, because that's CC CC CC CC CC CC CC CC as a double.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement