D - #define in D
- Andrew Edwards (12/12) Jul 04 2003 How would one accomplish the following in D?
- Walter (8/18) Jul 04 2003 const uint MATRIX_A = 0x9908b0df; /* constant vector a */
- Andrew Edwards (5/8) Jul 04 2003 Thanks Walter,
- Walter (3/12) Jul 04 2003 My mistake. Drop the const.
- Sean L. Palmer (4/10) Jul 05 2003 Heh.
- Sean L. Palmer (6/9) Jul 05 2003 Are those functions that return a const value or const functions?
How would one accomplish the following in D? <snip from metronome twister rng> #define MATRIX_A 0x9908b0dfUL /* constant vector a */ #define UMASK 0x80000000UL /* most significant w-r bits */ #define LMASK 0x7fffffffUL /* least significant r bits */ #define MIXBITS(u,v) ( ((u) & UMASK) | ((v) & LMASK) ) #define TWIST(u,v) ((MIXBITS(u,v) >> 1) ^ ((v)&1UL ? MATRIX_A : 0UL)) </snip from metronome twister rng> I read the "Converting C to D" and "The C Preproscesor vs D" pages but did not find a clear-cut example for the above cases. thanks in advance, Andrew
Jul 04 2003
"Andrew Edwards" <edwardsac spamfreeusa.com> wrote in message news:be4i4q$2vdt$1 digitaldaemon.com...How would one accomplish the following in D? <snip from metronome twister rng> #define MATRIX_A 0x9908b0dfUL /* constant vector a */ #define UMASK 0x80000000UL /* most significant w-r bits */ #define LMASK 0x7fffffffUL /* least significant r bits */ #define MIXBITS(u,v) ( ((u) & UMASK) | ((v) & LMASK) ) #define TWIST(u,v) ((MIXBITS(u,v) >> 1) ^ ((v)&1UL ? MATRIX_A : 0UL)) </snip from metronome twister rng> I read the "Converting C to D" and "The C Preproscesor vs D" pages but did not find a clear-cut example for the above cases.const uint MATRIX_A = 0x9908b0df; /* constant vector a */ const uint UMASK = 0x80000000; /* most significant w-r bits */ const uint LMASK = 0x7fffffff; /* least significant r bits */ const uint MIXBITS(uint u, uint v) { return (u & UMASK) | (v & LMASK); } const uint TWIST(uint u,uint v) { return (MIXBITS(u,v) >> 1) ^ (v&1 ? MATRIX_A : 0); }
Jul 04 2003
"Walter" <walter digitalmars.com> wrote...const uint MIXBITS(uint u, uint v) { return (u & UMASK) | (v & LMASK); } const uint TWIST(uint u,uint v) { return (MIXBITS(u,v) >> 1) ^ (v&1 ? MATRIX_A : 0); }Thanks Walter, However, the above lines generate the following error: mt.d(54): function MAXBITS functions cannot be const or auto would it be safe to just drop the const or is this a bug?
Jul 04 2003
"Andrew Edwards" <edwardsac spamfreeusa.com> wrote in message news:be4m35$25v$1 digitaldaemon.com..."Walter" <walter digitalmars.com> wrote...My mistake. Drop the const.const uint MIXBITS(uint u, uint v) { return (u & UMASK) | (v & LMASK); } const uint TWIST(uint u,uint v) { return (MIXBITS(u,v) >> 1) ^ (v&1 ? MATRIX_A : 0); }Thanks Walter, However, the above lines generate the following error: mt.d(54): function MAXBITS functions cannot be const or auto would it be safe to just drop the const or is this a bug?
Jul 04 2003
Heh. Sean "Walter" <walter digitalmars.com> wrote in message news:be504p$b7s$1 digitaldaemon.com...However, the above lines generate the following error: mt.d(54): function MAXBITS functions cannot be const or auto would it be safe to just drop the const or is this a bug?My mistake. Drop the const.
Jul 05 2003
Are those functions that return a const value or const functions? Does this type of construct tell the compiler that the function cannot have side-effects? Sean "Walter" <walter digitalmars.com> wrote in message news:be4kle$ji$1 digitaldaemon.com...const uint MIXBITS(uint u, uint v) { return (u & UMASK) | (v & LMASK); } const uint TWIST(uint u,uint v) { return (MIXBITS(u,v) >> 1) ^ (v&1 ? MATRIX_A : 0); }
Jul 05 2003