From Paul Edwards · 1996-03-27 04:09 · #73128 in FREE25
PE> The compiler will already know what the offset of a structure
PE> member will be, so I fail to see where the effort is involved in
PE> doing an "& 3". What did you base your "many times" with regard
PE> to compilation time on?
RH> Consider this:
RH> #pragma packed
RH> typedef struct {
RH> char foo;
RH> long int bar;
RH> } BadStruct;
RH> int proc1(long int *p)
RH> {
RH> return *p;
RH> }
RH> The argument to proc1 may or may not be aligned, depending on the alignment
RH> of p1 (it is when called from main(), it is not when called from proc2, as
RH> called from main()). The compiler would have to "walk through" the program
RH> to tell if proc1() is ever called with an aligned argument. Yes, at run
Being an external routine, it could be being called from elsewhere.
You have no choice but to do the test for alignment at runtime as
far as proc1 is concerned.
RH> time the access code could contain the test, but at compile time, the
RH> address is not available, instead it has to be determined by an in-depth
You've answered the question yourself here. There is no avoiding
the runtime check for alignment, which will not require indepth
compile analysis, just a runtime performance hit, same as
other systems, just worse. BFN. Paul.
---
* Origin: X (3:711/934.9)