Dmitry:
Probably yes, check out the assembler listing file when you compile the
source code. I don't have the Keil compiler so I can't check it. I'd
assume it either did a memcpy or perhaps STMIA/LDMIA assembler instructions.
If you needed to do that in gcc then I believe that memcpy(a,b,4) would
achieve the same result. I don't know if there is any direct equivalent to
__packed in gcc when casting variables.
IIRC isn't left-hand side casting behaviour "undefined" as per the C
specifications? I know it's convention to allow left-hand casting, but I
don't think it's part of the C specifications.
In gcc you can do structure packing like this:
// Master Boot Record
typedef struct {
unsigned char fill[0x1be]; // boot code
PARTENTRY partitions[4]; // partition table
unsigned char sig_55; // 55h boot signature
unsigned char sig_aa; // AAh boot signature
} __attribute__((packed)) MBR, *PMBR;
-- Sean
At 05:40 2/7/2006, you wrote:
>Sean,
>does it mean that
> *(__packed long *) a = *(long *)b;
>is actually
> memcpy(a,b,4)
>???
>
>Cheers,
>Dmitry.
>
>On Tuesday 07 February 2006 13:25, Sean wrote:
> > Dmitry:
> >
> > __packed means that there will be no gaps left around that
> > variable. Normally a long would be put on a 32-bit boundary, however the
> > __packed attribute tells the linker not to leave any adjacent space.
> >
> > Note that on the ARM7 chips if you attempt to access a halfword or word
> > that is not aligned properly the behaviour is "undefined". If 'a' is not
> > properly aligned that statement would not work. In this case this __packed
> > instructs the compiler that 'a' may not be aligned, so read/write it as a
> > series of 4 bytes instead of a directly as a 32-bit word.
> >
> > -- Sean
> >
> > At 04:26 2/7/2006, you wrote:
> > >Hi Bertrik,
> > >
> > > > Making the examples work with GCC involved byte-packing all USB related
> > > > structures and replacing compiler specific options with GCC
> > > > equivalents.
> > >
> > >Thanks a lot...
> > >
> > >I looked into KEIL's examples and found __packed keyword which appeared in
> > >the from of 'long'. I'm puzzled there, for example:
> > >
> > >char *a, *b;
> > >
> > >*(__packed long *) a = *(long *)b;
> > >
> > >how to interpret this???
> > >
> > >Cheers,
> > >Dmitry.Message
Re: [lpc2000] lpc2148 usb + gcc
2006-02-07 by Sean
Attachments
- No local attachments were found for this message.