program arguments in module constructor?

Georg Wrede georg.wrede at nospam.org
Tue May 16 15:30:26 PDT 2006


Chris Nicholson-Sauls wrote:
> Johan Granberg wrote:
> 
>> Can this bee done?
>>
>> //file.d
>> static this()
>> {
>>     char[][] args=getArgs();//
>>     someFunk(args);
>> }
>>
>> void main(char[][] args)
>> {
>>     runProgram();
>> }
>> //end of file
>>
>> Basically i want to access the args argument passed to main before 
>> main is called. I think that when we have module constructors we 
>> should bee able to do this (if we already can pleas tell me).
>>
>> (The problem i try to solve is working around the SDLmain hack to 
>> initialize SDL in the module constructor of my library so that when 
>> main is called the SDL will already bee initialized)
>>
>> Thanks in advance.
> 
> 
> I'm not sure how it might be accomplished in linux, but in Windows you 
> could use 'LPTSTR GetCommandLineA()' to retrieve it, but it will be as 
> 'char*' rather than 'char[][]'. There is 'LPWSTR* 
> CommandLineToArvW(LPCWSTR, int*)' to convert it to an argc/argv pair, 
> but it isn't available in ASCII mode that I know of.

And then there's the compatibility problem of different command line 
handling by the operating system.

In MSDOS "myprog foo.*" gives the program a single argument containing 
"foo.*".

In Linux, "myprog foo.*" gives the program either a command line with 
all the file names matching foo.*, or if there are none, the string 
foo.* itself.



More information about the Digitalmars-d mailing list