Hi,

stdint.h is a standard C header file. If you use it in VC, you need to download it from net and place it in the include folder.

If packing of struct is necessory, use "#pragma pack" compiler directive to resolve it. For example,

#include <stdint.h>

#pragma pack(1)

union U8x4_n_U32
{
    uint8_t u8[4];
    uint32_t u32;
};

#pragma pack()

SDCC will ignore the pragmas with an warning. GCC and VC would accept it without any problem.

I have to think about the endian-ness problem. Most probably I would write some #ifdef kind of statement to compile the specific part of the code that converts a long to its constituent bytes.

Krish

On Thu, May 5, 2011 at 3:13 PM, Maarten Brock <sourceforge.brock@dse.nl> wrote:
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