I don't understand what do you mean by "PORTABLE". Union is supported in sdcc, gnu-arm, gcc and visual C.
And I have not seen any document stating that the usage of union in C is bad :)


On Thu, May 5, 2011 at 1:10 PM, Philipp Klaus Krause <pkk@spth.de> wrote:
Am 05.05.2011 09:10, schrieb Krishnendu Chatterjee:
> Hi,
> My solution would be:
> #include <stdint.h>
> union […]

This seems to be the best so far, but none of the presented "solutions"
from this thread is portable or good C. Here's one that is:

unsigned char c[sizeof(unsigned long)];
unsigned long i;

memcpy(c, &i, sizeof(unsigned long));
memcpy(&i, c, sizeof(unsigned long));


WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today.  Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
Sdcc-user mailing list