2 ms·
This pertains only to C and C++ but the problem with printf type debugging is it might throw you off. Consider: int* foo = .... ... *foo = 123; printf(
by ensiferum 8y ago
This pertains only to C and C++ but the problem with printf type debugging is it might throw you off. Consider:
int* foo = ....
...
*foo = 123;
printf("killroy was here");
Now that code could actually print "killroy was here" but also crash on the pointer dereference. When this happens a naive developer will be thinking that the foo ptr access can't be the problem.
- mjw1007 8y agoAlas, the same problem has been known to happen with debugger-provided breakpoints and tracepoints. That's why GCC advertises -O0 as «make debugging produce the expected results» (which in practice will avoid the problem in your example too). There are lots of other ways to cause yourself trouble using printf to debug, of course (eg clobbering errno).