code在C printf函数 [英] Code for printf function in C

查看:142
本文介绍了code在C printf函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  的C / C ++函数源$ C ​​$ C

我想知道我在哪里可以找到C code,它的使用,所以当我写的printf(的Hello World!);在我的C PROGRAMM知道它具有打印字符串到stdout。我看了上述< stdio.h中>中但我只能找到它的原型int的printf(为const char *格式,...),但它并不怎么看起来像内部

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版本...你可以看到它传递标准输出 vfprintf

Here's the GNU version of printf... you can see it passing in stdout to vfprintf:

__printf (const char *format, ...)
{
   va_list arg;
   int done;

   va_start (arg, format);
   done = vfprintf (stdout, format, arg);
   va_end (arg);

   return done;
}

<一个href=\"http://sourceware.org/git/?p=glibc.git;a=blob;f=stdio-common/printf.c;h=4c8f3a2a0c38ab27a2eed4d2ff3b804980aa8f9f;hb=3321010338384ecdc6633a8b032bb0ed6aa9b19a\">See这里

下面的<一个href=\"http://sourceware.org/git/?p=glibc.git;a=blob;f=stdio-common/vfprintf.c;h=fc370e8cbc4e9652a2ed377b1c6f2324f15b1bf9;hb=3321010338384ecdc6633a8b032bb0ed6aa9b19a\">a链接到 vfprintf ...所有格式魔力在这里发生。

Here's a link to vfprintf... all the formatting 'magic' happens here.

这是真正的与众不同有关这些功能的唯一的事情是,他们使用可变参数的论点可变长度的参数列表来获得。除此之外,他们只是传统C.(这与帕斯卡的printf 等同,这与具体的支持,在编译器实现的......至少它是早在天。)

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.)

这篇关于code在C printf函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆