[Updated organization and content for clarity]
The Real Question
What would be a good way, for C, to help a programmer, while s/he's typing, write safe and correct calls to project-specific printf-like debugging functions?
C macros? C wrapper functions? Code editor macros or templates? Other?
Background Questions and Answers
Much software uses printf or printf-like functions for debugging, either ad-hoc when there's a problem, or for debug logs. And yet it's error-prone.
Q1: How do we know?
A1: Static analyzers have categories for printf-mismatch errors -- it's a common class of errors -- and I often see those tools call out those warnings on C code.
Q2: What are the sub-classes of this error?
A2: Mainly, wrong format specifier, and wrong number of format specifiers. Often the real error is the converse: wrong variable type, or wrong number of variables for print-out.
Q3: Why do we care?
A3: At best, causes wrong logging information and impedes debugging. At worst, crashes the software.
Q4: Has anyone tried to do anything about this problem?
A4: Sure, though I haven't seen any for C (as opposed to C++ or other), for example:
http://www.ddj.com/cpp/184401999?pgno=1 http://mi.eng.cam.ac.uk/~er258/cvd/tag/html/group__printf.html
What's missing for me in these offerings and others, besides the fact that right now I'm looking at a product written in C and need to solve the problem for C, is that they are after-the-fact solutions. They can avoid crashes, and can provide warning explanations of what went wrong, and that something went wrong, but they certainly can't guess what the programmer's intention was (see esp. Q&A #2 above).
Q5: Why is using printf so error-prone?
A5: Because writing a printf call requires the programmer to mix types and numbers of variables, format specifiers, free text string constants, and punctuation -- all of which look very similar to each other -- on one line together.