crash on args.getopt

Suliman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 24 11:39:48 PST 2015


First of all it's seems bug in docs:
void main(string[] args)
{
   getopt(
     args,
     "length",  &length,    // numeric
     "file",    &data,      // string
     "verbose", &verbose,   // flag
     "color",   &color);    // enum
   ...
}

with args inside getopt I am getting:
C:\D\dmd2\windows\bin\..\..\src\phobos\std\getopt.d(547): 
Deprecation: using * o
n an array is deprecated; use *(receiver).ptr instead
C:\D\dmd2\windows\bin\..\..\src\phobos\std\getopt.d(547): Error: 
cannot modify i
mmutable expression *cast(immutable(char)*)receiver
C:\D\dmd2\windows\bin\..\..\src\phobos\std\getopt.d(548): 
Deprecation: using * o
n an array is deprecated; use *(receiver).ptr instead

http://dlang.org/phobos/std_getopt.html

But problem that I do not know how handle not existing values:

void main(string[] args)
{
	args.getopt
	(
		"help", &help
	);
}

app.exe -sss
causes crash:
std.getopt.GetOptException at C:\D\dmd2\windows\bin\..\..\src\phobos\std\getopt.d(4
63): Unrecognized option -sss
----------------
0x00453F0E in @safe void std.getopt.getoptImpl!().getoptImpl(ref 
immutable(char)
[][], ref std.getopt.configuration) at 
C:\D\dmd2\windows\bin\..\..\src\phobos\st
d\getopt.d(463)


More information about the Digitalmars-d-learn mailing list