> |> register u_short *w = addr;
> |> register int sum = 0;
> |> u_short answer = 0;
> |> ....
> |> *(u_char*)(&answer) = *(u_char*)w;
> |> sum += answer;
> |>
> |> This is a dumb way to write this.
> |>
> |> egcs-19990405 generates code that gets the right value, others (including
> |> egcs-1.0.3 used to build RedHat-5.2, AFAIKS) break, as they don't respect
> |> the initialization and put a random byte in the higher half.
> |>
> |> A better way to write the above is just:
> |>
> |> sum += *(u_char*)w;
>
> This is not the same.
You are absolutely right: Endianness enters here. This should be:
#if __BYTE_ORDER == __LITTLE_ENDIAN
sum += *(u_char *)w;
#else
sum += (*(u_char *)w) << 8;
#endif
-- Horst von Brand vonbrand@sleipnir.valparaiso.cl Casilla 9G, Vi�a del Mar, Chile +56 32 672616- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/