Hacker News new | ask | show | jobs
by getsat 5357 days ago
Yes. You're not agreeing or disagreeing with me. Did you reply to the wrong post?

Also, using printf() for debugging? In 2011? I seriously hope you guys don't do this.

2 comments

"Also, using printf() for debugging? In 2011? I seriously hope you guys don't do this."

OK, I'll bite. I haven't done any serious straight up C programming in over a decade, and yes, I used a lot of printf for debugging back then. What's the best way to debug C programs now? (I imagine printf wasn't the best way to debug programs when I was writing C, either.) A different logging library? gdb?

printf() is fine if you just want to see if something is being run (assuming, of course, you recognize the flushing caveat we're discussing).

If you're dumping printf()s all over the place to see exactly what flow your program is taking at runtime, you're better off just setting a breakpoint or two and using a debugger to quickly step through it.

Adding a newline into a line buffer (which is a user-space buffer) flushes the buffered data up to and including the newline. fflush also flushes a user space buffer. Also, the "for those" implies I'm talking about someone else, not myself.