Better use a union for the (final) conversion, i.e int conv(unsigned char *c) { unsigned int i; union { unsigned int u; int i; } u;u.u = 0; for (i = 0; i < sizeof u; i++) u.u = (u.u << 8) + c[i]; return u.i; }
This is not portable, though; accessing a union member other than the member last stored into is unspecified behaviour (see J.1 and 6.2.6.1). This is allowed (and defined behaviour) as a GCC extension, though. Segher