need help
Boris Wang
nano.kago at hotmail.com
Mon Apr 24 23:10:26 PDT 2006
The suitable explain is :
args[ leftLimit .. rightLimit ]
the leftLimit is the first index, and the rightLimit is the
last index + 1, just equal with args.length.
but we used to write the following code:
for ( int i = 0; i < len - 1; i ++ )
....
"Boris Wang" <nano.kago at hotmail.com> 写入消息新闻:e2kdlg$1p04$1 at digitaldaemon.com...
> You are right, the args array begin from index 0, but
>
>> foreach( char[] arg; args[0 .. args.length] )
>
> This should not be right, it should be :
> foreach( char[] arg; args[0 .. args.length - 1] )
>
> and more, when i run the followed code:
>
> import std.stdio;
>
> int main( char[][] args )
> {
> foreach( char[] arg; args[0 .. args.length - 1 ] )
> {
> printf( "%s ", cast(char*)arg );
> }
> }
>
> it even produce a assert:
>
> Error: AssertError Failure hello_my.d(10)
>
>
> "Regan Heath" <regan at netwin.co.nz>
> ??????:ops8jr1mr223k2f5 at nrage.netwin.co.nz...
>> On Tue, 25 Apr 2006 11:13:58 +0800, Boris Wang <nano.kago at hotmail.com>
>> wrote:
>>> int main( char[][] args )
>>> {
>>> foreach( char[] arg; args[1 .. args.length] )
>>> {
>>> printf( "%.*s ", arg );
>>> }
>>>
>>> for ( int i = 0; i < args.length; i++ )
>>> {
>>> printf("%.*s ", args[i] );
>>> }
>>>
>>> return 0;
>>> }
>>>
>>> The first printf can't display the information, and the second do.
>>>
>>> I use dmd 0.154, XP SP2.
>>
>> The first one skips the first arg, to include the first arg use:
>>
>> foreach( char[] arg; args[0 .. args.length] )
>> {
>> printf( "%.*s ", arg );
>> }
>>
>> Apart from that they produce identical output for me.
>>
>> Regan
>
>
More information about the Digitalmars-d-learn
mailing list