Help translating C/C++ snippet to D

Mike Parker aldacron at gmail.com
Tue Jul 3 03:23:46 PDT 2012


On 7/3/2012 11:34 AM, Dustin wrote:
> Hello,
> I'm trying to follow along with a C++ tutorial and translate it to D but
> I don't know C/C++ well enough to understand this #Define statement:
>
> #define ARRAY_COUNT( array ) (sizeof( array ) / (sizeof( array[0] ) *
> (sizeof( array ) != sizeof(void*) || sizeof( array[0] ) <= sizeof(void*))))
>
> Can anyone help me understand this and translate it to a D function?
> Thanks for your time.

There is no reason to translate this to D. C++ doesn't keep track of 
array lengths out of the box, so programmers either have to do it 
themselves or implement some hackery like this macro to figure it out. 
In D, none of that is necessary.

myArray.length

Same thing.





More information about the Digitalmars-d-learn mailing list