R
ramasubramanian.rahul
hi
i was doing some tinkering and wrote the following code on a HPUX
#include<stdio.h>
2 int main(){
3 char *buf = malloc( 100 );
4 int a = * ( int * ) ( buf + 13 );
5 }
this thing prompyly gave a bus error
i know that this is an example of misaligned access .. i believe that
the compiler expects to get an aligned address ( 4 bytes in this case )
....and since the address is odd its flaunders.
on Intel machine it works fine
my doubt is :
why does the compiler expect to get an aligned address... why can it
not take a misaligned address? what is main reason for alignment... and
slightly digressing... why is alignment of stack necessary ( gcc
compiler keep doing that some how ).......
a detailed answer will be highly appriciated
thanks in advance
kind egards
rahul
i was doing some tinkering and wrote the following code on a HPUX
#include<stdio.h>
2 int main(){
3 char *buf = malloc( 100 );
4 int a = * ( int * ) ( buf + 13 );
5 }
this thing prompyly gave a bus error
i know that this is an example of misaligned access .. i believe that
the compiler expects to get an aligned address ( 4 bytes in this case )
....and since the address is odd its flaunders.
on Intel machine it works fine
my doubt is :
why does the compiler expect to get an aligned address... why can it
not take a misaligned address? what is main reason for alignment... and
slightly digressing... why is alignment of stack necessary ( gcc
compiler keep doing that some how ).......
a detailed answer will be highly appriciated
thanks in advance
kind egards
rahul