Convert this C macro kroundup32 to D mixin?

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Apr 8 03:02:01 PDT 2017


On Saturday, 8 April 2017 at 09:53:47 UTC, biocyberman wrote:
>
> What is the D mixin version equivalent to this macro:
>
> #define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, 
> (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x))
>
> The macro looks cryptic. What the macro does has been explained 
> here: 
> http://stackoverflow.com/questions/3384852/could-someone-help-explain-what-this-c-one-liner-does
>
> But I still don't know how to convert that to D mixin. I would 
> like 'mixin' instead of a function is to avoid function call 
> overhead. Also because it is short, so I think a mixin is 
> enough, not a 'template mixin'.

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


More information about the Digitalmars-d-learn mailing list