Should writef try to statically check for format specifiers?

bearophile bearophileHUGS at lycos.com
Mon Apr 11 14:38:08 PDT 2011


Andrej Mitrovic:

> I realize runtime checks would be out of the question, but I'm looking for compile-time checks when it's possible to do so.

GCC is often able to catch such bugs, but Walter has recently closed my enhancement request about this :-(
http://d.puremagic.com/issues/show_bug.cgi?id=4458

So a solution is to build a fwrite/fwriteln that uses a compile-time string for formatting, that performs compile-time tests using the more efficient CTFE of DMD 2.053:

int foo, bar;
fwriteln!"%d %s"(foo, bar); // compile-time error: bar isn't a string!

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list