Ada front-end depends on signed overflow
Segher Boessenkool
segher@kernel.crashing.org
Mon Jun 6 11:28:00 GMT 2005
> 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
More information about the Gcc
mailing list