writef %d of string
Stewart Gordon
smjg_1998 at yahoo.com
Thu Dec 1 07:45:54 PST 2011
On 12/10/2011 23:41, bearophile wrote:
> This code, that a sane language/language implementation refuses at compile-time, runs:
It's perfectly legal code, so the best a compiler can correctly do is give a warning.
Some C(++) compilers understand printf and will warn if the format string doesn't match
the arguments, but even this is rare AIUI.
To enforce well-formed format strings at compile time would require it to be made a
language builtin. Or maybe template metaprogramming can do it.
> import std.stdio;
> void main() {
> writefln("%d", "hello");
> }
>
>
> And it outputs:
> ['h', 'e', 'l', 'l', 'o']
>
> Is this good/expected/acceptable/buggy?
It certainly should either throw an exception or generate more sane output such as Andrej
is getting. What DMD version are you using?
Stewart.
More information about the Digitalmars-d-learn
mailing list