Creating A D DLL For Use By VB
Regan Heath
regan at netwin.co.nz
Tue Mar 21 00:27:39 PST 2006
On Tue, 21 Mar 2006 06:28:20 +0000 (UTC), Rory Starkweather
<Rory_member at pathlink.com> wrote:
>>> if (Args.length > 1)
>>> {
>>> printf("Received %d args.\n", Args);
>>
>> Don't you mean:
>> printf("Received %d args.\n",Args.length);
>>
>> the odd thing is, it doesn't crash without it!?
>>
>
> Good point. Interesting too because the number printed
> out is correct.
I've just realised why :)
An array in D is essentially a structure in the form:
struct array {
int length;
void *data;
}
When you pass an array to printf you're essentially passing the address of
the start of that struct, in other words the address of the length 'int'.
It's the reason why this also works:
char[] test = "test";
printf("%.*s\n",test);
the length int is found first, and is used for the '*'. The data pointer
is next and is used for the 's'.
>> You should probably start to use writef instead of printf.
>
> This is my third day with D. I had planned to wait until tomorrow for
> the hard stuff. ;}
No worries.
Regan
More information about the Digitalmars-d-learn
mailing list