[En-Nut-Discussion] Next release 4.10?

Harald Kipp harald.kipp at egnite.de
Mon May 9 11:47:52 CEST 2011


Hi Thiago,

On 5/9/2011 4:23 AM, Thiago A. Corrêa wrote:
>      I guess it should be safe to fix it as:
> 
> s = (cp[2] << 8) & 0xFF00;
> s |= cp[3];

 s = cp[2] << 8;
 s |= cp[3];

(without "& 0xFF00") is just fine. However, the following will make it
even more fool proof:

 s = cp[2];
 s <<= 8;
 s |= cp[3];

There are weird compilers, which require

 s = (uint16_t)cp[2] << 8;

to avoid shifting an 8-bit value, losing all bits.

 s <<= 8;

is unambiguously. I assume, that the GCC optimizer is smart enough to
generate the same code from both versions.

Regards,

Harald




More information about the En-Nut-Discussion mailing list