Loading ...
Sorry, an error occurred while loading the content.

8283RE: [nslu2-linux] Re: Requirements for OpenDebianSlug and some otherquestions

Expand Messages
  • John Bowler
    Sep 1, 2005
    • 0 Attachment
      From: dyoung8888
      >From: Jon Pounder
      >> You've got me curious - how could a programmer actually cause that ?
      >> it up to the compiler to pad to the alignment boundaries when it
      >> storage locations ? or would it take something like
      >> char[n]
      >> and then read (word)char[1]

      Correct - the compiler gets it right, the programmer has to fool the
      compiler somehow, the above is, indeed, the normal method.

      >have a look at http://groups.yahoo.com/group/nslu2-linux/message/8122

      Or go back to around the start of the year when it was discussed at length.
      The result was written up in this wiki page:


      The only common C programming technique which will cause a mis-aligned
      access is a cast - strictly what is called reinterpret_cast in C++ (i.e. a
      static_cast is always safe, as are const_cast and dynamic_cast). The
      trivial test case (in C++):

      #include <iostream>
      #include <iomanip>
      int main(void) {
      char buffer[8];
      for (int i(0); i<8; ++i)
      buffer[i] = i;
      int *ptr = reinterpret_cast<int*>(buffer+1);
      std::cout << std::hex << *ptr << std::endl;
      return 0;

      Which will cause an alignment fault on ARM and, instead of outputing (big
      endian) 01020304 will probably output 01020300

      John Bowler <jbowler@...>
    • Show all 17 messages in this topic