Hi all, When portability is an issue my concerns would be endianness and packing which none of the posts have addressed. C does not guarantee much about the position of fields in a union or a struct or the position of bytes in a long int.
Maarten > 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)); > > Philipp > > ------------------------------------------------------------------------------ > 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. > http://p.sf.net/sfu/whatsupgold-sd > _______________________________________________ > Sdcc-user mailing list > Sdcc-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/sdcc-user > > ------------------------------------------------------------------------------ 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. http://p.sf.net/sfu/whatsupgold-sd _______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user