Hi,
I try to confirm my understanding of word alignment by writing a
program that screw this particular matter up.
I run linux on:
Intel(R) Core(TM)2 CPU T7600 @ 2.33GHz
my compiler is:
gcc version 4.1.2
I compile with no arguments other than source file name and target
name (-o ptr_test).
I write this program but it doesn't crash. Is it because I'm testing
the wrong thing (my understanding is wrong) or is it because my
environment is very forgiving?
#include <stdlib.h>
#include <stdio.h>
int main( int argc, char** argv )
{
char* ptr = malloc( 32 );
ptr++;
*(int*)ptr = 20;
printf("ptr: %d\n", *ptr );
*(int*)ptr = *(int*)ptr + 20;
printf("ptr: %d\n", *ptr );
return(0);
}
Thanks
/Sune