By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,678 Members | 1,175 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,678 IT Pros & Developers. It's quick & easy.

Inline code in header files - learned my lesson, but one mystery remains

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"S Austin" <Fu***********@mindspring.com> wrote...
Discovered recently (duh) [...]
[...] 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?
Is that a question? I don't know whether you can or cannot.
The simplest answer is that you used different compiler options
when compiling your executable and your library. They do need to
be synchronised rather carefully, you know. It's a big PITA, if
you ask me.
[...]
FYI BCB 5.0 on Win XP.


I would ask in the compiler newsgroup, luckily there is one.

Victor
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.