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 the format string isn't even known at compile time in the first place?

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.

As I understand it.

http://www.acronymfinder.com/ is your friend.

And GCC (and Clang too) do it, so it's not a rare thing.

I meant rare among the world's various C compilers.  Are you going by usage 
statistics?

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.

What do you mean by a "built-in rule" exactly?

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.
<snip>

Maybe there's a way that the template instances can be very small, delegating most of the work to non-templated functions.

Stewart.

Reply via email to