FIX: Inline Functions Instantiated when Not Referenced

Last reviewed: September 18, 1997
Article ID: Q116371
7.00 | 1.00 1.50 MS-DOS | WINDOWS kbtool kbfixlist kbbuglist

The information in this article applies to:

  • The Microsoft C/C++ Compiler (CL.EXE), included with:

        - Microsoft C/C++ for MS-DOS, version 7.0
        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
    

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:

  • Because this behavior occurs when the functions are defined as "inline" but not referred to in the code, use compiler directives such as "#ifndef" to exclude the function from being compiled.

    - or -

  • Either compile the source code without any debugging information (no /Zi option) or compile using the fast compiler (with the /f compiler option).

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 : CLIss kb16bitonly kbbuglist kbfixlist kbtool
Version : 7.00 | 1.00 1.50
Platform : MS-DOS WINDOWS
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.