printf() with no arguments in C compiles fine. how?

前端 未结 10 1983
后悔当初
后悔当初 2020-12-02 00:10

I tried the below c program & I expected to get compile time error, but why compiler isn\'t giving any error?

#include 
int main(void)
{
          


        
10条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 00:54

    Using g++ with commandline parameter -Wall produces the following diagnostics:

    g++ -Wall   -c -g -MMD -MP -MF "build/Debug/MinGW-Windows/main.o.d" -o build/Debug/MinGW-Windows/main.o main.cpp
    main.cpp: In function 'int main(void)':
    main.cpp:17:16: warning: format '%d' expects a matching 'int' argument [-Wformat=]
         printf("%d");
                    ^
    

    That's pretty useful, isn't it?

    gcc/g++ also check if the format specifiers actually match the parameter types. This is really cool for debugging.

提交回复
热议问题