On Thu, Jan 11, 2018 at 04:38:57PM -0500, Steven Schveighoffer via 
Digitalmars-d-announce wrote:
> On 1/11/18 4:12 PM, kdevel wrote:
> > On Thursday, 11 January 2018 at 20:40:01 UTC, Dmitry Olshansky wrote:
> > > What did you expect?
> > 
> > To be honest: A compile time error. Modern C compilers can check such
> > format strings. Example: GCC 6:
> But dmd isn't a C compiler, nor does it have to worry about the problems C
> has (namely, untyped varargs). To dmd, printf is just another function,
> there's nothing special about it.

Yeah, checking C-style printf formats isn't dmd's problem.

The Phobos equivalent of printf, however, *does* support compile-time
format checking in the latest version:

        writefln!"%s %d %d"("abc", 1); // "Orphan format specifier: %d"
        writefln!"%s %d"("abc", 1, 2); // "Orphan format arguments: args[2..3]"
        writefln!"%s %d"(1, "abc");    // "Incorrect format specifier for 
range: %d"
        writefln!"%f"(1);              // "incompatible format character for 
integral argument: %f"

Best of all, this is all done via CTFE in the library code, no
hard-coding in the compiler necessary.  You can implement your own
compile-time checker for your own DSLs in the same way, without needing
to hack the compiler.


MSDOS = MicroSoft's Denial Of Service

Reply via email to