FIX: Inline Functions Instantiated when Not Referenced

ID: Q116371

7.00 | 1.00 1.50 MS-DOS | WINDOWS kbtool kbfixlist kbbuglist

The information in this article applies to:

SYMPTOMS

If a function is defined as "__inline" and is not referred to in the code, the inline function is still instantiated. This happens in the C/C++ Compiler, versions 8.0 and 8.0c, when you use either the /Zi or both the /f- and /AL compiler options. When you use the C/C++ Compiler, version 7.0, the error occurs only when you use the /Zi compiler option.

RESOLUTION

To work around this problem, do one of the following:

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed above. This is not a problem in Visual C++, 32-bit Edition. This problem was corrected in Visual C++ version 2.0.

MORE INFORMATION

The inline and _inline keywords allow the compiler to insert a copy of the function body in each place where the function is called. The substitution occurs at the discretion of the compiler.

If the following sample code is compiled using /Zi (or /f- and /AL if using Visual C++), the linker returns an "unresolved external" error on "_somevariable". Because the function "func()" is not being referred to in the code, the compiler does not instantiate it unless the compiler options mentioned above are used. If func() is instantiated, the linker tries to resolve the reference to _somevariable, and, not finding it, generates the "unresolved external" error.

Sample Code

/* Compile options needed: /Zi or /f- /AL
*/ 

   extern int somevariable;

   __inline void func()
   {
      somevariable=1;
   }

   void main(void)
   {
   }

Additional reference words: 1.00 1.50 7.00 8.00 8.00c KBCategory: kbtool kbfixlist kbbuglist KBSubcategory: CLIss
Keywords          : kb16bitonly kbCompiler kbbuglist kbfixlist
Version           : 7.00   | 1.00 1.50
Platform          : MS-DOS WINDOWS
Solution Type     : kbfix

Last Reviewed: September 22, 1997