Microsoft KB Archive/116371

{|
 * width="100%"|

FIX: Inline Functions Instantiated when Not Referenced

 * }

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 : kb16bitonly kbCompiler

Issue type :

Technology : kbVCsearch kbAudDeveloper kbCVCComp