Hi Dmitry, Thanks, this makes some sense now. I wish Keil had documented the __packed better (I looked at the manual on their web site but it doesn't discuss a __packed typecast and I would never have guessed that the typecast actually rearranges the array memory!) I'll give this a go next. Thanks also for your info bdmlpc. Kind regards, Nic > Hi Nic, > I had the same problem... > It seems that Keil's __packed keyword in the front of a pointer > effectively > means > memcpy(packed_p, source_p, sizeof(source)); > > In your case your can write > EP0Buf[0] = 0; > EP0Buf[1] = 0; > or just > *(short *)EP0Buf = 0; > if you add __atribute__((aligned(2))) to the EP0Buf declaration: > char __atribute__((aligned(2))) EP0Buf[USB_MAX_PACKET0]; > This will in result write to assembly: > .comm EP0Buf, USB_MAX_PACKET0, 2 > where last digit '2' is an optional align passed to linker. > > Have fun, > Dmitry. > > P.S. in my case I couldn't run Keil's example on my board with gcc anyway. > > > > On Tuesday 28 February 2006 05:54, weartronics wrote: >> Dear lpc2000, >> >> In the Keil LPC2148 USB examples, EP0 buffer is declared as a byte array >> BYTE EP0Buf[USB_MAX_PACKET0]; >> >> but later it is type cast to the packed word array >> *((__packed WORD *)EP0Buf) = 0; >> >> I don't understand how the pointer EP0Buf would be changed by casting >> it to the __packed word pointer. Is anyone able to explain the >> function of the type cast to me so I can write a GCC equivalent (where >> the type cast to a packed type is not supported)? >> >> Thanks, >> >> Nic >> >> >> >> >> >> >> Yahoo! Groups Links >> >> >> > > > > Yahoo! Groups Links > > > > > > > >
Message
Re: [lpc2000] type cast in GCC
2006-02-28 by nic@weartronics.com
Attachments
- No local attachments were found for this message.