Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Inline code in header files - learned my lesson, but one mystery remains

Reply
Thread Tools

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

 
 
S Austin
Guest
Posts: n/a
 
      01-29-2004
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
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      01-29-2004
"S Austin" <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Header files with "header.h" or <header.h> ?? mlt C++ 2 01-31-2009 02:54 PM
Multiple functions (one version being inline and other beingnon-inline) Rahul C++ 3 02-28-2008 03:28 PM
Program uninstalled, but it remains on HD and in "Add/Remove Progr =?Utf-8?B?QW1hdyBPcGF3?= Windows 64bit 4 08-06-2007 10:28 PM
HP 820cse - Problem solved, mystery remains pgluth1 A+ Certification 0 01-16-2006 07:55 PM
Function delcared inline but not defined inline Nish C Programming 4 10-08-2004 03:31 PM



Advertisments