次の方法で共有


Using Function Name Without "()" Produces No Code

OverviewHow Do I

Feature Only in Professional and Enterprise Editions   Code optimization is supported only in Visual C++ Professional and Enterprise Editions. For more information, see .

When a function name declared in your program is used without parentheses, the compiler does not produce any code. The compiler may not produce error messages or warnings as long as the function has been prototyped. This occurs regardless of whether or not the function takes parameters because the compiler calculates the function address; however, because the function call operator "()" is not present, no call is made. This result is similar to the following:

   int a;
   a;      /* no code generated here either */

In Microsoft 32-bit Visual C++ , even using warning level 4 generates no diagnostic output. No warning is issued; no code is produced.

The sample code below compiles and links correctly without errors but produces no code in reference to funcn( ). For this to work correctly, add the function call operator "()".

#include <stdio.h>

void funcn();

void main( void )   {
   funcn;      /* missing function call operator;
                  call will fail.  Use funcn() */
   }

void funcn()
{
   printf("\nHello World\n");
}