www.digitalmars.com         C & C++   DMDScript  

D - Array bug?

reply MicroWizard <MicroWizard_member pathlink.com> writes:
I have found this problem. (DMD 0.81)
When I run this program with any arguments, it works as I expect.
But without arguments, it seems to me, that the length property of array arg can
not be queried. An exception is thrown.

Is it a bug or am I completely confused?

Best regards,
Tamás (microwizard ax.hu)

--Results-----------------------------
C:\Work\DottProp>dmd exctest.d
C:\dmd\bin\..\..\dm\bin\link.exe exctest,,,user32+kernel32/noi;

C:\Work\DottProp>exctest
Debug 1.
Debug 2.
Error occured: Error: Access Violation

C:\Work\DottProp>exctest kuka
Debug 1.
Debug 2.
Debug 3.

--exctest.d--------------------------------------------
void main(char[][] arg)
{
try
{
printf("Debug 1.\n");
if(!arg)
{
throw new Error("No args.");
}
printf("Debug 2.\n");
if(arg.length<2)
{
throw new Error("Nothing to do.");
}
printf("Debug 3.\n");
}
catch(Error e)
{
printf("Error occured: %s ... Aborting.\n",e.toString());
}
catch(Exception e)
{
printf("Exception occured: %s ... Aborting.\n",e.toString());
}
catch
{
printf("Unexpected exception occured.\n");
}
}
--Finish-------------------------------
Mar 11 2004
parent "C. Sauls" <ibisbasenji yahoo.com> writes:
Nope, no array bug, printf() bug.  Change your %s specifiers to %.*s and 
it works fine.  This is because D's strings are of arbitrary length and 
not null-terminated.  Your hint should have been that your "...Aborting" 
message never showed up in the error report.  :)

-C. Sauls
-Invironz

MicroWizard wrote:
 I have found this problem. (DMD 0.81)
 When I run this program with any arguments, it works as I expect.
 But without arguments, it seems to me, that the length property of array arg
can
 not be queried. An exception is thrown.
 
 Is it a bug or am I completely confused?
 
 Best regards,
 Tamás (microwizard ax.hu)
 
 --Results-----------------------------
 C:\Work\DottProp>dmd exctest.d
 C:\dmd\bin\..\..\dm\bin\link.exe exctest,,,user32+kernel32/noi;
 
 C:\Work\DottProp>exctest
 Debug 1.
 Debug 2.
 Error occured: Error: Access Violation
 
 C:\Work\DottProp>exctest kuka
 Debug 1.
 Debug 2.
 Debug 3.
 
 --exctest.d--------------------------------------------
 void main(char[][] arg)
 {
 try
 {
 printf("Debug 1.\n");
 if(!arg)
 {
 throw new Error("No args.");
 }
 printf("Debug 2.\n");
 if(arg.length<2)
 {
 throw new Error("Nothing to do.");
 }
 printf("Debug 3.\n");
 }
 catch(Error e)
 {
 printf("Error occured: %s ... Aborting.\n",e.toString());
 }
 catch(Exception e)
 {
 printf("Exception occured: %s ... Aborting.\n",e.toString());
 }
 catch
 {
 printf("Unexpected exception occured.\n");
 }
 }
 --Finish-------------------------------

Mar 11 2004