> -----Original Message-----
> From: Tal [
tal
spam_OUTzapta.com]
> Sent: Saturday, April 26, 2003 12:55 PM
> To: 'pic microcontroller discussion list'
> Subject: RE: [PIC]: How to split a 16bit into two (2) 8bits
>
>
> Hi Dan
>
> >
> > I wasn't aware that the C standard allowed padding between
> > consecutive byte array elements. Which section allows that?
>
> Good question. The standard do allow padding in some integer values:
>
> "For unsigned integer types other than unsigned char, the
> bits of the object representation shall be divided into two
> groups: value bits and padding bits (there need not be any of
> the latter)." from
http://std.dkuug.dk/jtc1/sc22/open/n2794/n2794.pdf
>
> Which means for example that a 16 bit value may occupy by
> more than 16 bits. This is probably to address architectures
> that have addressing and alignment restrictions.
>
> I posted a question in comp.lang.c. Let's see what the C
> 'lawyers' say.
>
> Tal
>
>
> > -----Original Message-----
> > From: pic microcontroller discussion list
> > [
@spam@PICLISTKILLspam
MITVMA.MIT.EDU] On Behalf Of Ned Konz
> > Sent: Saturday, April 26, 2003 10:40 AM
> > To:
KILLspamPICLISTKILLspam
MITVMA.MIT.EDU
> > Subject: Re: [PIC]: How to split a 16bit into two (2) 8bits
> >
> >
> > On Saturday 26 April 2003 10:22 am, Tal wrote:
> > > This solution is efficient but note that it is based on
> some hidden
> > > assumptions about the compiler implementation details such
> > as the data
> > > representation used by the compiler (little endian vs. big
> > endian vs.
> > > something else, no padding between byte array elements, etc).
> >
> > I wasn't aware that the C standard allowed padding between
> > consecutive byte array elements. Which section allows that?
> >
> > The endianness of the given compiler is likely to remain
> > constant. But I agree; you'd normally put this into a macro
> > and use a #define for the endianness:
> >
> > #define LS_BYTE 0
> > #define MS_BYTE 1
> >
> > union { uint16 w; uint8 b[2] } u;
> > u.w = my16BitNumber;
> > writeByte(u.b[ LS_BYTE ]);
> > writeByte(u.b[ MS_BYTE ]);
> >
> > --
> > Ned Konz
> >
http://bike-nomad.com
> > GPG key ID: BEEA7EFE
> >
> > --
> >
http://www.piclist.com hint: To leave the PICList
>
RemoveMEpiclist-unsubscribe-requestTakeThisOuT
mitvma.mit.edu
>