This is the mail archive of the crossgcc@sourceware.org mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Compiler Memory Alignment Issue


Richard:

It probably doesn't cause the result you're seeing, but the size of your buffer[] (8 bytes) is one byte smaller than that which you are reading and printing (9 bytes: 0 - 8).

PROGRAM:

#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<unistd.h>

int main()
{
         unsigned char buffer[8], i;
         int *ptr = (int *) buffer;

         printf("size of int is: %d\n", sizeof(int));
         memset(buffer, 0xff, sizeof buffer);

*(ptr + 1) = 0x1234;

         for (i=0; i<(sizeof(buffer) +1); i++)
                 printf("buffer[%d]=%x\n", i, buffer[i]);
}




--
For unsubscribe information see http://sourceware.org/lists.html#faq


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]