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
#pragma pack(1)
union U8x4_n_U32
{
uint8_t u8[4
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 Chatter
Am 05.05.2011 09:51, schrieb Krishnendu Chatterjee:
> Hi,
>
> 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 :)
>
The problem is not the union. However ui
Hi,
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
:)
Krish
On Thu, May 5, 2011 at 1:10 PM, Philipp Klaus Krause wrote:
> Am 05.05.2011 09:10, schrieb Krishne
Am 05.05.2011 09:10, schrieb Krishnendu Chatterjee:
> Hi,
>
> My solution would be:
>
> #include
>
> 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 l
Hi,
My solution would be:
#include
union U8x4_n_U32
{
uint8_t u8[4];
uint32_t u32;
};
union U8x4_n_U32 u8x4_n_u32;
// uint32_t to array of uint8_t conversion
u8x4_n_u32.u32 = 0xA0459201;
/**
** Now you can access the individual bytes as
** u
Hi,
I would use something like:
for (i=0; i<4; i++)
char_counter[i] = ((unsigned char*)&long_counter)[i];
for (i=0; i<4; i++)
((unsigned char*)&long_counter)[i] = char_counter[i];
Hynek
Dne 4.5.2011 4:08, stof...@skulp.net napsal(a):
Hi, I have to transmit an unsigned long as four bytes
On Wed, 4 May 2011, Kevin Bailey wrote:
On Wed, May 4, 2011 at 7:31 PM, Erik Petrich
wrote:
long_counter = (unsigned int)(char_counter[0] | (char_counter[1] << 8)) |
((unsigned long)(char_counter[2] | (char_counter[3] << 8)) << 16);
I hope the first (unsigned int) cast isn't necessar
On Wed, May 4, 2011 at 7:31 PM, Erik Petrich
wrote:
>
>
> long_counter = (unsigned int)(char_counter[0] | (char_counter[1] << 8)) |
> ((unsigned long)(char_counter[2] | (char_counter[3] << 8)) << 16);
I hope the first (unsigned int) cast isn't necessary, because the
char_counter[1] << 8 wo
On Thu, 5 May 2011, Kristoffer Ek wrote:
>
> On 4.5.2011, at 6:20, Erik Petrich wrote:
>
>> long_counter = (char_counter[0] | (char_counter[1] << 8)) |
>> ((unsigned long)(char_counter[2] | (char_counter[3] << 8)) << 16);
>
>
> This overflows at 32767 :-/
>
> -- stoffer
Sorry, I didn't ta
On 4.5.2011, at 6:20, Erik Petrich wrote:
> long_counter = (char_counter[0] | (char_counter[1] << 8)) |
> ((unsigned long)(char_counter[2] | (char_counter[3] << 8)) << 16);
This overflows at 32767 :-/
-- stoffer
---
On Wed, 4 May 2011, stof...@skulp.net wrote:
> Hi, I have to transmit an unsigned long as four bytes, so I split them up
> and join them again, but with the folowing example code, I get overflow at
> long_counter>32767 - can any of you give me a clue how to do it right?
> // split long_co
12 matches
Mail list logo