S
S Austin
Discovered recently (duh) that putting inline code in .h files (e.g.
in class definitions) is not a good idea when building DLLs and the
applications that use those DLLs. The reason being, of course, is
that the application gets its own copy of that code when it compiles
and won't call the code in the DLL. Each compiled unit in the DLL also
ends up with its own copy of the never-called code.
Assuming the same build process for the DLL and the application,
theoretically this shouldn't be that big a deal...however, I only
discovered the error of my ways when the program didn't run right. It
turns out that the offsets into member variables were getting computed
differently by the compiler when it built the DLL and the application.
In other words, the inline function code built into the application
didn't use the same offsets to member variables as the code in other
functions implemented in the DLL.
I can't explain why this would be the case?
The specific case I encountered was that the address stored into a
32-bit pointer was different by one byte. Certainly strange enough to
think that an odd-numbered address would ever be computed by the
compiler when there were no individual char's in the class and all
char arrays had power-of-two lengths.
Stepping through the machine code in the debugger revealed the bug -
the constant offset added to the base register was 12 in functions
within the DLL and 13 within the inline functions in the application.
Needless to say jumping into a data structure one byte past its
starting address screwed things up royally.
FYI BCB 5.0 on Win XP.
Cheers
S. Austin
in class definitions) is not a good idea when building DLLs and the
applications that use those DLLs. The reason being, of course, is
that the application gets its own copy of that code when it compiles
and won't call the code in the DLL. Each compiled unit in the DLL also
ends up with its own copy of the never-called code.
Assuming the same build process for the DLL and the application,
theoretically this shouldn't be that big a deal...however, I only
discovered the error of my ways when the program didn't run right. It
turns out that the offsets into member variables were getting computed
differently by the compiler when it built the DLL and the application.
In other words, the inline function code built into the application
didn't use the same offsets to member variables as the code in other
functions implemented in the DLL.
I can't explain why this would be the case?
The specific case I encountered was that the address stored into a
32-bit pointer was different by one byte. Certainly strange enough to
think that an odd-numbered address would ever be computed by the
compiler when there were no individual char's in the class and all
char arrays had power-of-two lengths.
Stepping through the machine code in the debugger revealed the bug -
the constant offset added to the base register was 12 in functions
within the DLL and 13 within the inline functions in the application.
Needless to say jumping into a data structure one byte past its
starting address screwed things up royally.
FYI BCB 5.0 on Win XP.
Cheers
S. Austin