warning: format not a string literal and no format arguments

后端 未结 3 996
小蘑菇
小蘑菇 2020-11-27 04:27

I want to remove the warning that i get on this line of the code,

FILE *fil;
char *imp;
(...)
fprintf(fil,imp);

the thing is when i do thi

3条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 04:42

    I think the accepted answer explained it very well. Basically, as the documentation also indicates, the compiler can not guarantee that the string variable (in this case imp) is a string literal. You may disable this warning if you are not concerened with safety by puting

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

    in the header of your code or in the CMake:

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

提交回复
热议问题