Notes from C++ static analysis

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Jun 26 12:33:59 PDT 2013


On 6/26/13 11:08 AM, bearophile wrote:
> On the other hand this D program prints just
> "10" with no errors, ignoring the second x:
>
> import std.stdio;
> void main() {
> size_t x = 10;
> writefln("%d", x, x);
> }
>
> In a modern statically typed language I'd like such code to give a
> compile-time error.

Actually this is good because it allows to customize the format string 
to print only a subset of available information (I've actually used this).

> This is how how Rust gets this right:
>
> println(fmt!("hello, %d", j))
>
> https://github.com/mozilla/rust/blob/master/src/libsyntax/ext/fmt.rs
> https://github.com/Aatch/rust-fmt

This is potentially inefficient because it creates a string instead of 
formatting straight in the output buffer.


Andrei


More information about the Digitalmars-d mailing list