How to translate this C macro to D mixin/template mixin?
VitaliiY
yvitaliy1980 at yandex.ru
Tue Jun 15 12:18:26 UTC 2021
Could anybody help with translation of this C macro to D
mixin/mixin template? Here a - unsigned char, b - int. It's
simple with STARTDATA as mixin, but STOREBITS and ADDBITS use
variables defined in STARTDATA scope, so I can't understand how
to do mixin template with it.
#define STARTDATA \
size_t ressize=0; \
char *blockstart; \
int numbits; \
uint64_t bitbuffer=0;
#define STOREBITS \
while(numbits >= 8) \
{ \
if(!size) return 0; \
*(buffer++) = bitbuffer>>(numbits-8); \
numbits -= 8; \
++ressize; \
--size; \
}
#define ADDBITS(a, b) \
{ \
bitbuffer = (bitbuffer<<(a))|((b)&((1<<a)-1)); \
numbits += (a); \
STOREBITS \
}
More information about the Digitalmars-d-learn
mailing list