digitalmars.D.learn - Help translating C/C++ snippet to D
- Dustin (9/9) Jul 02 2012 Hello,
- nazriel (8/17) Jul 02 2012 http://dpaste.dzfl.pl/481e26b6
- Dustin (2/21) Jul 03 2012 Thanks so much!!
- Tongzhou Li (3/16) Jul 03 2012 Bye!
- Mike Parker (7/14) Jul 03 2012 There is no reason to translate this to D. C++ doesn't keep track of
- Dustin (3/24) Jul 03 2012 Ok cool that's why I like D much more than C++, it gets rid of a
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.
Jul 02 2012
On Tuesday, 3 July 2012 at 02:34:04 UTC, 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.http://dpaste.dzfl.pl/481e26b6 It's quite simple. Macros in C++, should be replaced with their successor - templates. In case of D, we haven't got macros per se, so we need to use template. In example above I just used template'd function.
Jul 02 2012
On Tuesday, 3 July 2012 at 04:09:22 UTC, nazriel wrote:On Tuesday, 3 July 2012 at 02:34:04 UTC, Dustin wrote:Thanks so much!!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.http://dpaste.dzfl.pl/481e26b6 It's quite simple. Macros in C++, should be replaced with their successor - templates. In case of D, we haven't got macros per se, so we need to use template. In example above I just used template'd function.
Jul 03 2012
On Tuesday, 3 July 2012 at 02:34:04 UTC, 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.Just use this:int[123] i; writeln(i.length);int* p; writeln(p.length); // Compile errorBye!
Jul 03 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.
Jul 03 2012
On Tuesday, 3 July 2012 at 10:23:06 UTC, Mike Parker wrote:On 7/3/2012 11:34 AM, Dustin wrote:Ok cool that's why I like D much more than C++, it gets rid of a lot of ambiguity. Thanks for the info.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.
Jul 03 2012