On 02/12/2011 03:19, bearophile wrote:
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 :-)
You mean all programming languages should support CTFE for argument validation?
What if
Stewart Gordon:
You mean all programming languages should support CTFE for argument
validation?
This is not necessary, and it's not sufficient...
What if the format string isn't even known at compile time in the first place?
In this case the format string validation is done at run-time.
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
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.
This code, that a sane language/language implementation refuses at
compile-time, runs:
import std.stdio;
void main() {
writefln(%d, hello);
}
And it outputs:
['h', 'e', 'l', 'l', 'o']
Is this good/expected/acceptable/buggy?
Bye,
bearophile
That's a sweet trick right there. I get different results but I guess
this is due to new std.format changes:
[104, 101, 108, 108, 111]