Word alignment - Why doesn't this crash?
- From: ollemblomgren@xxxxxxxxx
- Date: Mon, 31 Mar 2008 03:46:03 -0700 (PDT)
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
.
- Follow-Ups:
- Re: Word alignment - Why doesn't this crash?
- From: Andrey Tarasevich
- Re: Word alignment - Why doesn't this crash?
- From: Philip Potter
- Re: Word alignment - Why doesn't this crash?
- Prev by Date: Re: case labels
- Next by Date: Re: [ot]Re: printf and cout
- Previous by thread: we need some data on line
- Next by thread: Re: Word alignment - Why doesn't this crash?
- Index(es):
Relevant Pages
|