Word alignment - Why doesn't this crash?



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
.



Relevant Pages

  • Re: curious about array initialization.
    ... Keith Thompson wrote: ... means its a base of knowledge by which you have universal understanding ... the compiler doesn't have to allocate storage for the string literal. ... That the standard is not something from which you can derive ...
    (comp.lang.c)
  • Re: Replacing fgets
    ... Even if u_int8_t is a typedef for unsigned char, ... Didn't your compiler complain here. ... offset is changed ... offset needs to be an int. ...
    (comp.lang.c)
  • Re: howto get rid of pointer arguments differ in signedness
    ... why don't you provide some argument supporting your 'total ... disagreement' with the idea that C-compilers should support ... Since the specification is ten years younger than 'the compiler', ... char and unsigned char are three mutually incomaptible types, ...
    (comp.os.linux.development.apps)
  • Re: Need support for the IBM support
    ... So the only compiler we have is XL eval with the most recent patches. ... provide a freely-accessible bug reporting web page, ... int main(int argc, char *argv) { ... this=2ff224a0 S(const char* char array) ...
    (comp.unix.aix)
  • Re: regcmp warning: improper pointer/integer combination: op "="
    ... Type casting is in the standard because there are cases where it can ... an implementation-defined header provides a prototype ... requires the compiler to assume that it ... result to char* doesn't fix the problem, ...
    (comp.lang.c)