Why doesn’t putchar require a header?

后端 未结 2 1022
一生所求
一生所求 2021-01-20 19:53

Reading this answer which explains the polyglot program on page not found on Stack Overflow I was surprised to read putchar was used because you don\'t need a

2条回答
  •  迷失自我
    2021-01-20 20:08

    In c, you can use any function without a declaration.

    The compiler then assumes, that the function has a return type of int. The parameters are passed to the function as given. Since there is no function declaration, the compiler cannot verify, if the parameters are correct.

    putchar is not builtin into the compiler. However, since

    The function call putchar(c) shall be equivalent to putc(c,stdout).

    it might be defined as a macro, e.g.

    #define putchar(c) putc(c, stdout)
    

    In this case, you must include stdio.h to have the correct definition for putchar.

提交回复
热议问题