Setting default values for Main function's args Array

wjoe invalid at example.com
Thu Jun 27 17:19:03 UTC 2019


On Thursday, 27 June 2019 at 17:05:05 UTC, Vaidas wrote:
> Is it possible to set the default values for the Main 
> function's arguments?
> It seems that I'm getting Range error.
>
>>import std.stdio : writeln;
>>void main(string[] args = ["asdsfasdf", "asdklfajsdk", 
>>"asdfasdfasd"]){
>> 
>>    writeln("", args[1]);
>>}
>
> Output:
>>vaidas at vaidas-SATELLITE-L855:~/Desktop$ rdmd newfile.d
>>>core.exception.RangeError at newfile.d(4): Range violation
>>----------------
>>??:? _d_arrayboundsp [0x555f5b79f8e9]
>>??:? _Dmain [0x555f5b79e7ee]

consider this:

module d-program;

void main(string[] args)
{
   import std.stdio;
   writeln("args = ", args);
}

---

~/> ./d-program abc def

Output:
args = ["~/d-program", "abc", "def"]

---

~/> ./d-program

Output:

args = ["~/d-program"]


More information about the Digitalmars-d-learn mailing list