C语言中printf函数的代码
可能的重复:
c/c++函数源代码
我想知道在哪里可以找到 C 代码当我写 printf("Hello World!"); 时使用在我的 C 程序中,要知道它必须将该字符串打印到 STDOUT。我查看了
Possible Duplicate:
source code of c/c++ functions
I was wondering where I can find the C code that's used so that when I write printf("Hello World!"); in my C programm to know that it has to print that string to STDOUT. I looked in <stdio.h>, but there I could only find its prototype int printf(const char *format, ...), but not how it looks like internally.
这是
printf
的 GNU 版本...您可以看到它将stdout
传递到vfprintf
:参见此处。
这是链接 到
vfprintf
...所有格式化“魔法”都发生在这里。这些函数唯一真正“不同”的是它们使用可变参数来获取可变长度参数列表中的参数。除此之外,它们只是传统的 C。(这与 Pascal 的
printf
等效项形成对比,后者是在编译器中的特定支持下实现的......至少在当时是这样。)Here's the GNU version of
printf
... you can see it passing instdout
tovfprintf
:See here.
Here's a link to
vfprintf
... all the formatting 'magic' happens here.The only thing that's truly 'different' about these functions is that they use varargs to get at arguments in a variable length argument list. Other than that, they're just traditional C. (This is in contrast to Pascal's
printf
equivalent, which is implemented with specific support in the compiler... at least it was back in the day.)