我正在使用 VS2015 和/Wall 编译一个 C++ 文件。
我正在使用 printf
函数。
我得到:
warning C4710: 'int printf(const char *const ,...)': function not inlined
我了解内联。我在 MS 环境中看到了有关 __forceinline
的帮助。我只是不明白为什么 VS2015 没有通过 stdio.h
正确使用它并且仍然生成警告。
我的stdio.h
文件在这里:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt
有什么办法可以解决这个问题吗?
编辑:
好的示例代码如下:
int main(int argc, char** argv){
printf("Hello World\n");
return 0;
};
至于我是想用C还是C++,我目前是用Windows开发的,但是文件最终会在HPUX上编译成C。如果这是警告的原因,我也想知道。
最佳答案
编译器尝试内联一些函数(在本例中为 printf()
以实现性能或磁盘空间,如 here in the documentation 所述。但是,您可以通过以下方式禁用这些警告:
#ifdef _WIN32
#pragma warning (disable : 4710)
#endif
或在 CMake 中:
if (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_C_FLAGS "/wd4710")
endif()
编辑:
在现代惯用的 CMake 中,最好避免直接编辑 CMAKE_C_FLAGS 变量。
您可以改为执行以下操作。
add_compile_options(
$<$<C_COMPILER_ID:MSVC>:/wd4710>
)
或者您甚至可以只针对单个目标禁用警告
target_compile_options(YourTargetName
$<$<C_COMPILER_ID:MSVC>:/wd4710>
)
关于c++ - VS2015 提示 printf 没有内联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49245647/