Thread overview
#define in D
Jul 04, 2003
Andrew Edwards
Jul 04, 2003
Walter
Jul 04, 2003
Andrew Edwards
Jul 04, 2003
Walter
Jul 05, 2003
Sean L. Palmer
Jul 05, 2003
Sean L. Palmer
July 04, 2003
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


July 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); }


July 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?


July 04, 2003
"Andrew Edwards" <edwardsac@spamfreeusa.com> wrote in message news:be4m35$25v$1@digitaldaemon.com...
> "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?

My mistake. Drop the const.


July 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); }



July 05, 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.