This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
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).
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |