title: How does #pragma align work?
body: <p>I recently ran into an embedded C program using the '#pragma align' directive:</p>
  
  <pre><code>/*
   * Audio buffers
   */
  #pragma align(4)
  static uint32_t RxBuffer1[NUM_AUDIO_SAMPLES];
  
  #pragma align(4)
  static uint32_t RxBuffer2[NUM_AUDIO_SAMPLES];
  
  #pragma align(4)
  static uint32_t TxBuffer1[NUM_AUDIO_SAMPLES];
  
  #pragma align(4)
  static uint32_t TxBuffer2[NUM_AUDIO_SAMPLES];
  </code></pre>
  
  <p>Note that this code excerpt is for a DSP chip, thus it's not x86-64.</p>
  
  <p>After doing some research, this appears to be a method for aligning variables in memory at a specified distance. For example, it would allow me to align three char vars at 1 byte intervals as opposed to placing them in the typical memory word width (e.g. 4 byte intervals). I understand that there are some penalties involved with storing variables at non-word intervals. This is due to the fact that memory is retrieved as words, thus it would be necessary to do shifting and masking if you were trying to just look at individual bytes.</p>
  
  <p>However, I'm confused with how '#pragma align' is actually implemented. So my primary question: how does it work?</p>
  
  <p>I'm hoping to get some comments regarding the following items:
  - Is the '#pragma align' directive a common thing? Or is it dependent on the environment you're working in (i.e. does #pragma align exist for x86).
  - Why is this a preprocessor directive? Why is the preprocessor responsible for this?
  - What goes on behind the scenes when I later want to reference one of these oddly aligned variables? What does it reference to be able to know that 'variable x is byte 3 of memory word 0x1ABA9'. </p>
  
  <p>Edit: I'm just now realizing that the #pragma directive is intended for machine specific compilers, thus the answer to my question may be heavily influenced by the environment I'm working in. To give you more information, I'm working with an Analog Devices Blackfin+ processor. A link to that chip is provided <a href="http://www.analog.com/en/products/processors-dsp/blackfin/adsp-bf706.html#product-documentation" rel="nofollow">here</a>.</p>