I seem to be able to crash writefln

Jonathan M Davis jmdavisProg at gmx.com
Wed Mar 9 23:31:21 PST 2011


On Wednesday 09 March 2011 23:15:13 Andrew Wiley wrote:
> On Wed, Mar 9, 2011 at 5:19 PM, Joel Christensen <joelcnz at gmail.com> wrote:
> > This is on Windows 7. Using a def file to stop the terminal window coming
> > up.
> > 
> > win.def
> > EXETYPE NT
> > SUBSYSTEM WINDOWS
> > 
> > bug.d
> > import std.stdio;
> > import std.string;
> > 
> > void main() {
> >        auto f = File( "z.txt", "w" );
> >        scope( exit )
> >                f.close;
> >        string foo = "bar";
> >        foreach( n; 0 .. 10 ) {
> >                writefln( "%s", foo );
> >                f.write( format( "count duck-u-lar: %s\n", n ) );
> >        }
> > }
> > 
> > output (from in z.txt):
> > count duck-u-lar: 0
> 
> My understanding is that the "0..10" isn't actually a range notation,
> and you need to use iota(0, 10). I may be wrong, but if I'm right,
> hopefully someone can explain why this syntax works?
> I remember there being a discussion about this recently; I'll see if I
> can find it.

0..10 works with foreach. It's specific to foreach. iota also works, because it 
produces a range rather being built in to the language. As such, iota works in 
places _other_ than foreach. But 0..10 works just fine in foreach. It definitely 
pre-dates iota.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list