array and pointers

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Thu Jan 25 12:34:48 PST 2007


Anders F Björklund wrote:
> Frits van Bommel wrote:
> 
>> Nitpick: the members are the other way around :p. (in DMD)
>> Not that it usually matters, but this may come up when writing inline 
>> assembly or calling extern(C) functions.
>> This is not in the spec though, so it's implementation-dependent.
> 
> If you're going to nitpick, then it's implemented as a ulong
> (32-bit length | 32-bit ptr) in DMD and as a struct in GDC...
> This makes a difference for return values. Or when debugging.
> And it definitely will later, when D supports 64-bit as well.
> 
> But most of the time, you can just use .length and .ptr :-)

Well, AFAIK the only real difference between ulongs and 8-byte structs 
is how they're returned from extern(C) functions (and perhaps 
extern(Windows/Pascal) as well).

The only reason I even *know* that is that several functions (e.g. 
_d_arrayappendT (previously _d_arrayappend) in Phobos) have their 
calling conventions all screwed up ;).
They get parameters passed like a C function, but return an array like a 
D function would.
This doesn't actually matter to the typical user, since they're only 
called internally by compiler-generated code that expects exactly that.
So for every-day use, I'd say the struct is way easier to understand and 
correct enough :p.


More information about the Digitalmars-d-learn mailing list