Range violation

Mike Parker aldacron at gmail.com
Fri Nov 24 11:19:14 UTC 2017


On Friday, 24 November 2017 at 09:59:13 UTC, Vino wrote:

> if (args.length < 1 || args.length > 2) {
> 	writeln(args[0].baseName, ":No Arguments Provided");
> 	exit(-1);
> 		}

When you pass no arguments, this won't execute as args.length 
will still be 1, the only argument being the path to the 
executable -- args[0], of which you are apparently already aware. 
The if conditional should be this to test for no args:

if(args.length == 1)

> string op = args[1];

Because the above conditional passes when you pass no args, this 
causes a range violation since args[1] doesn't exist.


More information about the Digitalmars-d-learn mailing list