Compiler Memory Alignment Issue
Rod Nussbaumer
bomr@triumf.ca
Thu Feb 2 23:26:00 GMT 2012
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
More information about the crossgcc
mailing list