Eric
Eric

Reputation: 19863

VS2015 complains about printf not inlined

I'm compiling a C++ file with VS2015 and /Wall. I'm using the printf function.

I get:

warning C4710: 'int printf(const char *const ,...)': function not inlined

I understand about inlining. I've seen help about __forceinline in MS environment. I just don't understand why VS2015 is not using it properly through stdio.h and still generate the warning.

My stdio.h file is here:

C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt

Is there any way to get rid of this?

Edit:

Ok sample code goes like this:

int main(int argc, char** argv){
  printf("Hello World\n");
  return 0;
};

As for whether I want to use C or C++, I'm currently using Windows for development, but the file will eventually be compiled as C on HPUX. If this is the reason for the warning, I'd like to know as well.

Upvotes: 3

Views: 2074

Answers (1)

Foad S. Farimani
Foad S. Farimani

Reputation: 14016

The compiler tries to inline some functions (in this case printf() in order to achieve performance or disk space, as described here in the documentation. However, you can disable these warnings by:

#ifdef _WIN32
#pragma warning (disable : 4710)
#endif

or in the CMake:

if (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
  set(CMAKE_C_FLAGS "/wd4710") 
endif()

Edit:

In modern idiomatic CMake, it's best to avoid directly editing the CMAKE_C_FLAGS variable.

You can do the following instead.

add_compile_options(
  $<$<C_COMPILER_ID:MSVC>:/wd4710>
)

Or you can even disable the warnings only for a single target with

target_compile_options(YourTargetName
  $<$<C_COMPILER_ID:MSVC>:/wd4710>
)

Upvotes: 2

Related Questions