News for hackers. Stuff that matters.
Re:Type-Safe Printf for C by WalterBright on Tuesday December 14, 2021 @03:42PM (#29557336)
D supports calling C functions directly, including printf. When we added printf format checking against the arguments, many bugs were exposed and fixed. It was a big win.
Re:Type-Safe Printf for C by kazinator on Tuesday December 14, 2021 @05:48PM (#29559199)
GCC has this also; this work is different because it removes the type errors. Instead of having an error like "%d expects a parameter of type int, not char ", it just lets %d print the string anyway. It's more like format* in Lisp, say:

  [1]> (format t "~05,'0d" 5)
  00005
  NIL
  [2]> (format t "~05,'0d" "abc")
  00abc
  NIL
Here ~d (decimal) doesn't care that it didn't get an integer.
Re:Type-Safe Printf for C by WalterBright on Tuesday December 14, 2021 @07:33PM (#29560281)
For D's formatted write function, %s means "I don't care what type it is, just do the write thing with it" which works fine for nearly all uses.