putc需要stdout,vs puts

bob*_*obo 4 c history stdio

C历史问题在这里.为什么C函数putc需要第二个参数

putc( 'c', stdout ) ;
Run Code Online (Sandbox Code Playgroud)

虽然看起来很方便哦

puts( "a string" ) ;
Run Code Online (Sandbox Code Playgroud)

msvc ++中有一个函数

putchar( 'c' ) ;
Run Code Online (Sandbox Code Playgroud)

哪种方式可以按照预期的方式putc工作.我认为第二个参数putc是能够指向putc文件,但有一个功能fputc.

Cra*_*lus 10

int putc ( int character, FILE * stream );
Run Code Online (Sandbox Code Playgroud)

将字符写入流并推进位置指示器.
所以它是一个比putchar
其他函数更基础的功能,例如

#define putchar(c) putc((c),stdout)  
Run Code Online (Sandbox Code Playgroud)

根据Kernighan的书putc相当于fputcputc可以实现为宏,并且putc 可能不得不多次评估其流参数.
我已经读过,据说两者都存在向后兼容性,但不确定这是否有效