Convert this C macro kroundup32 to D mixin?
Mike Parker via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Apr 8 03:09:47 PDT 2017
On Saturday, 8 April 2017 at 10:02:01 UTC, Mike Parker wrote:
>
> I would expect if you implement it as a function the compiler
> will inline it. You can always use the pragma(inline, true) [1]
> with -inline to verify.
>
> [1] https://dlang.org/spec/pragma.html#inline
This gives me no error, so it does inline it.
T kroundup32(T)(T x) {
pragma(inline, true);
--(x);
(x)|=(x)>>1;
(x)|=(x)>>2;
(x)|=(x)>>4;
(x)|=(x)>>8;
(x)|=(x)>>16;
return ++(x);
}
More information about the Digitalmars-d-learn
mailing list