Re: Word alignment - Why doesn't this crash?



ollemblomgren@xxxxxxxxx wrote:

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?


There's no such thing as some mandatory "word alignment". Alignment requirements are type-specific and platform-specific. It is quite possible that in your platform objects of type 'int' can be placed in memory in any way you want, i.e. there are no alignment restrictions as all.

Note also, that the real "platform" you are working with is really the platform provided (emulated) by the compiler. It doesn't necessarily have to inherit all (or any) requirements from the underlying hardware platform. Normally it does for performance reasons, but it is not impossible to implement a C compiler that wouldn't impose any alignment restrictions on any of its data types, even though the underlying hardware platform does have such restriction for "corresponding" hardware data types.

--
Best regards,
Andrey Tarasevich
.



Relevant Pages

  • Re: how to get aliagned memory using malloc
    ... > Some told me that for memory to be aligned, the last 6 digits of the ... It depends on the internals of your platform. ... have restrictions on where certain data types may be placed, ... is why it is part of the implementation of a compiler. ...
    (comp.lang.c)
  • Re: how to get aliagned memory using malloc
    ... >>Some told me that for memory to be aligned, the last 6 digits of the ... It depends on the internals of your platform. ... > have restrictions on where certain data types may be placed, ... > is why it is part of the implementation of a compiler. ...
    (comp.lang.c)
  • Re: Can we use cpp to write WDM driver ?
    ... platform in there too. ... have broken so much code despite the DDK and others inventing its own ... data types long ago. ...
    (microsoft.public.development.device.drivers)
  • Re: A Query
    ... Sharad Kala wrote: ... >>Hello Grp, ... >Try out some newsgroup dedicated for your platform. ... if you don't like the data types or the functions names, ...
    (comp.lang.cpp)
  • Re: C performance
    ... >> anymore. ... Just change the data types to double and move on. ... Which is faster on your platform? ... (2reply remove FOOBAR) ...
    (comp.lang.c)