writef %d of string

bearophile bearophileHUGS at lycos.com
Thu Dec 1 19:19:06 PST 2011

Stewart Gordon:

>It's perfectly legal code,<

If that code is legal, then in my opinion it's the rules of the language that are wrong and in need to be changed :-)

>Some C(++) compilers understand printf and will warn if the format string doesn't match the arguments, but even this is rare AIUI.<

I don't know what 'AIUI' means. And GCC (and Clang too) do it, so it's not a rare thing.

>To enforce well-formed format strings at compile time would require it to be made a language builtin.<

Or just a built-in rule, as in GCC.

>Or maybe template metaprogramming can do it.<

Of course. It's not hard to create something like this:
writelnt!"%d %f"(53, 1.55);

But I think you need a D compiler able to remove unneeded template instantiations from the binary, to avoid bloat.

>It certainly should either throw an exception or generate more sane output such as Andrej is getting.  What DMD version are you using?<

I am using 2.057GitHead on 32 bit Windows. I don't know if this Phobos bug is in bugzilla.


More information about the Digitalmars-d-learn mailing list