?
\\
Hello,
my question could be a dumb question, but refers to some of the
strange
tips and tricks that the C language permits (not only it).
Suppose I have to work to set a bit in a variable, based on a bit of
another variable:
if (a & 0x04)
b |= 0x02;
else
b &= ~0x02;
some programmers like to clear the bit always before:
b &= ~0x02;
if (a & 0x04)
b |= 0x02;
or even:
b &= ~0x02;
b |= (a & 0x04) >> 1;
Which is best for *efficiency* ?
There are some references on the net that discuss all these C
shortcuts
or I have to look the code around for the rest of my life?
Thanks,
gaetano
my question could be a dumb question, but refers to some of the
strange
tips and tricks that the C language permits (not only it).
Suppose I have to work to set a bit in a variable, based on a bit of
another variable:
if (a & 0x04)
b |= 0x02;
else
b &= ~0x02;
some programmers like to clear the bit always before:
b &= ~0x02;
if (a & 0x04)
b |= 0x02;
or even:
b &= ~0x02;
b |= (a & 0x04) >> 1;
Which is best for *efficiency* ?
There are some references on the net that discuss all these C
shortcuts
or I have to look the code around for the rest of my life?
Thanks,
gaetano