Re: [Sdcc-user] overflow in supposed to be unsigned long

2011-05-04 Thread Hynek Sladky
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

Re: [Sdcc-user] overflow in supposed to be unsigned long

2011-05-04 Thread Erik Petrich
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

Re: [Sdcc-user] overflow in supposed to be unsigned long

2011-05-04 Thread Kevin Bailey
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

Re: [Sdcc-user] overflow in supposed to be unsigned long

2011-05-04 Thread Erik Petrich
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

Re: [Sdcc-user] overflow in supposed to be unsigned long

2011-05-04 Thread Kristoffer Ek
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 ---