Skip to main content
T J
Senior III
February 9, 2018
Question

how to align a char table to 32bit boundry

  • February 9, 2018
  • 2 replies
  • 1622 views
Posted on February 09, 2018 at 01:51

How can I force a char array to align 4 ?

//align 4;

char LoRaTxFrames[8][64];  

char LoRaRxFrames[8][64];

is this a correct method ?

char LoRaTxFrames[8][64];  __attribute__((packed, aligned(4)))

char LoRaRxFrames[8][64];  __attribute__((packed, aligned(4)))

#alignment
    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    February 9, 2018
    Posted on February 09, 2018 at 02:08

    Most compilers on ARM align structures and elements on 32-bit boundaries unless you change the packing

    #pragma pack(1) // tight packing, ie file structures, or third party data

    #pragma pack(4) // normal

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    S.Ma
    Principal
    February 9, 2018
    Posted on February 09, 2018 at 02:13

    There should be USB examples for 32 bit aligned 8 bit arrays needs.

    Usually, if I need 32 bit aligned, why not creating a type with union of u8[4] and u32 ?

    This maybe enough for the linker to get a clue of the 32 bit alignment need.

    A quick check with MAP file to find out.

    T J
    T JAuthor
    Senior III
    February 9, 2018
    Posted on February 09, 2018 at 04:52

    My purpose is to validate a packet by hash algorithm.

    actually, the array was already aligned, but I wanted to force the alignment to be sure future compilations still work.

    I am running a 32bit hash over the buffer, rather than doing the 8bit shuffle.

    AvaTar
    Senior III
    February 9, 2018
    Posted on February 09, 2018 at 07:44

    Things like memory alignment are core and toolchain specific, so there is no solution that fits for every environment.

    Just to mention that.