How to align array on 4byte boundary with Yagarto compiler

I need to align a buffer on a 4 byte boundary (means last 2 bits of the address must be zero). I’m currently declaring my buffer like this:

volatile unsigned char backBuffer[2][FRAME_SIZE] __attribute__ ((aligned(4)));

Abode code doesn’t align it, but the address is fixed.

Then I though of allocating memory and adjusting it to a boundary, like this:

volatile unsigned char* backBuffer[2];

backBuffer[0] = RLPext->malloc(FRAME_SIZE + 4);
backBuffer[1] = RLPext->malloc(FRAME_SIZE + 4);

while ((unsigned long)backBuffer[0] & 0x3)

while ((unsigned long)backBuffer[1] & 0x3)

but sometime, when I run the code one of the buffers is still not aligned correctly.

What am I missing?

Oops, posted too early!

__attribute__ ((aligned(4)));

is working (I checked the .map file), but for a quick copy function in assembler it needed to be 8 bytes aligned :slight_smile:


 __attribute__ ((aligned(8))); 

did the job.

@ WouterH - see, it pays to talk out loud :smiley:

Yeah, if I could step through the RLP code, I would have seen it going wrong :slight_smile: