title: Alignment in android NDK project
body: <p>I have an existing C++ project which I would like to port to android. Unfortunately the program causes an "Fatal signal 7 (SIGBUS)" error on android. It is working fine on other platforms (32bit/64bit Linux and Windows). Here is the part of the code, that causes the problem:</p>
  
  <pre><code>RawMem3::RawMem3(uint8_t packet_version, uint32_t flags, uint64_t packet_id,
      uint64_t packet_nr, uint64_t timestamp, vector&lt;uint16_t&gt;&amp; nr_channels,
      vector&lt;uint16_t&gt;&amp; samples_per_channel, vector&lt;double&gt;&amp; data) :
      size_(0) {
  
  size_ = sizeof(packet_version) + sizeof(size_) + sizeof(flags)
          + sizeof(packet_id) + sizeof(packet_nr) + sizeof(timestamp)
          + nr_channels.size() * sizeof(boost::uint16_t)
          + samples_per_channel.size() * sizeof(boost::uint16_t)
          + data.size() * sizeof(float); // FIXXXXXME  ...  hardcoded sizeof() !!!!
  
  mem_ = malloc(size_);
  
  uint8_t* ui8_ptr = reinterpret_cast&lt;uint8_t*&gt;(mem_);
  *ui8_ptr++ = packet_version;
  
  uint32_t* ui32_ptr = reinterpret_cast&lt;uint32_t*&gt;(ui8_ptr);
  *ui32_ptr++ = size_;
  *ui32_ptr++ = flags;
  
  uint64_t* ui64_ptr = reinterpret_cast&lt;uint64_t*&gt;(ui32_ptr);
  *ui64_ptr++ = packet_id;
  *ui64_ptr++ = packet_nr;
  
  uint64_t* time_ptr = reinterpret_cast&lt;uint64_t*&gt;(ui64_ptr);
  *time_ptr++ = timestamp;
  
  uint16_t* ui16_ptr = reinterpret_cast&lt;uint16_t*&gt;(time_ptr);
  
  for (unsigned int n = 0; n &lt; nr_channels.size(); n++)
      *ui16_ptr++ = nr_channels[n];
  for (unsigned int n = 0; n &lt; samples_per_channel.size(); n++)
      *ui16_ptr++ = samples_per_channel[n];
  
  try {
      float* flt_ptr = reinterpret_cast&lt;float*&gt;(ui16_ptr);
      for (unsigned int n = 0; n &lt; data.size(); n++)
          *flt_ptr++ = numeric_cast&lt;float&gt;(data[n]);
  } catch (negative_overflow&amp; e) {
      cerr &lt;&lt; "RawMem -- Constructor: " &lt;&lt; e.what();
  } catch (positive_overflow&amp; e) {
      cerr &lt;&lt; "RawMem -- Constructor: " &lt;&lt; e.what();
  } catch (bad_numeric_cast&amp; e) {
      cerr &lt;&lt; "RawMem -- Constructor: " &lt;&lt; e.what();
  }
  </code></pre>
  
  <p>Strictly speaking its this part:</p>
  
  <pre><code>uint32_t* ui32_ptr = reinterpret_cast&lt;uint32_t*&gt;(ui8_ptr);
  *ui32_ptr++ = size_;
  *ui32_ptr++ = flags
  </code></pre>
  
  <p>I guess it is an alignment problem. I am not a specialist in that stuff, so any ideas how i can fix this? I have already tried to change <code>packet_version</code> to a <code>uint32_t</code>. After that the SIGBUS error is gone, however my client software assuming that <code>packed_version</code> is a <code>uint8_t</code>. I can't change the client code so I need to fix this in a different way.</p>