[Info-vax] Dave Cutler, Prism, DEC, Microsoft, etc.

JF Mezei jfmezei.spamnot at vaxination.ca
Mon Nov 30 16:12:54 EST 2009


The Compiler guy was heard typing:

>> Remember that except for compiler bugs, alignment faults comes from the user
>> lying to the compiler.


Excuse me, but are there really circumstances where the programmer
("user" from Mr Reagan point of view) is lying to the compiler ?

if I have a 100 byte record, and bytes 7 though 10 inclusively contain
an integer, and I do:

myint = (int *) &(buffer + 6) ; /* hopefully I have the syntax right*/

In what way am I lying ?  Does the compiler realise that this will be an
unaligned access or will it be accusing me of lying ?


Out of curiosity, why do some CPUs have so much trouble fetching 4 bytes
from an unaligned location ? Is it the CPU and CPU architecture that is
the problem, or the RAM memory subsystem that can't fetch 4 bytes
starting at an uneven memory address ?

>> if you can't, tell the compiler
>> what you did and we'll avoid the alignment fault.

In C, how can I tell a compiler that trying to move 4 bytes into an
integer variable MAY cause an alignment fault ? With variable record
structures for instance, the location of an integer may vary and
sometimes be un an uneven offset from start of buffer. But you won't
know that at compile time since it would vary from record to record as
you process a file for instance.


BTW, does the X86-64 have similar performance handicap when trying to
fetch an integer from unaligned memory location ?



More information about the Info-vax mailing list