功能定义 [英] function definition

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

问题描述

亲爱的所有人!


在寻找printf函数的实现时,我实现了

整个实现

使用以下构造


int printf(const char * format,...)


"是什么意思... " ;?我在K& R书中找不到它,并且

正在寻找......在网上看起来似乎并不富有成效。该函数的实际

实现是一段工作代码,

我成功编译了它。

这是引入的方式$ c $ b C语言中的泛型编程范例?


谢谢。

解决方案

< blockquote> eotcl写道:


亲爱的所有人!


在寻找printf函数的实现时,我来了/>
整个实现

使用以下构造


int printf(const char * format,...)


" ..." ;?的含义是什么?我在K& R书中找不到它,并且

正在寻找......在网上看起来似乎并不富有成效。



搜索省略号C给出更好的结果?


例如 http://en.wikipedia.org/wiki/Ellipsis#In_programming


这应该会引导你''可变函数''


例如
http://en.wikipedia.org/wiki/Variadi...-C_and_C。 2B.2B


该函数的实际

实现是一段工作代码,

我成功地编译了它。

这是在C语言中引入通用编程范例的方式吗?


谢谢。



再见,Jojo


eotcl写道,On 29/09/08 18:01:


亲爱的所有人!


在寻找printf函数的实现时,我来了

实现

使用以下构造


int printf(const char * format,...)


...的含义是什么?我在K& R书中找不到它,而且



你需要提高自己的技能......

或者你需要获得第二版K& R,因为它是

之一的新 1989年或更早版本推出的功能。不要丢弃你的

第一版副本,它可能是值得的;-)


我的K& R2副本的索引告诉我我要看第155页和第202页,以及

我认为这两页中的第一页更容易学习。


look对于......在网上看起来似乎并不富有成效。实际的



尝试搜索变量参数列表或可变长度参数

列出或类似的,可能包括引号。请注意,虽然网上出现的很多内容都是错误的,通常是你不会发现的。

但是,comp.lang.c常见问题解答在 http://c-faq.com/ 优于平均水平
< blockquote class =post_quotes>
函数的实现是一段工作代码,

我设法成功编译它。



这是一件奇怪的事情。您的实现应该随附

您可以使用的printf实现!


这是在<引入泛型编程范例的方式吗? br />
C语言?



C中的泛型编程是一个比...更大的主题,包括使用宏和void *指针的

。 />
-

Flash Gordon

如果发送垃圾信息我将其发送至 sm**@spam.causeway.com

如果给我发电子邮件,请使用我的回复地址

请参阅我所主办的comp.lang.c Wiki http://clc-wiki.net/


9月30日凌晨1点01分,eotcl< eotc ... @ gmail.comwrote:


亲爱的所有人!


在寻找printf函数的实现时,我在整个实现中来了

使用以下构造的



int printf(const char * format,...)

" ..." ;?的含义是什么?我在K& R书中找不到它,并且

正在寻找......在网上看起来似乎并不富有成效。该函数的实际

实现是一段工作代码,

我成功编译了它。

这是引入的方式

C语言中的泛型编程范例?


谢谢。



在非常闲置的条款中,...表示补充格式的参数。


例如,这个非常简单的函数:


void psycho_printf(const char * format,...)

{

va_list ap;


fprintf(stderr,Charles Manson说:);

va_start(ap,format);

vfprintf(stderr,format,ap);

va_end(ap);

fprintf (stderr," \ n");


返回;

}


可以调用喜欢:


psycho_printf("%s%s%d",foo,bar,intfoo);


或:


psycho_printf("%s",foo);


如您所见,省略号允许未确定数量的

参数。 C库中的printf核心是一个角落案例。我的例子

很糟糕,我没有返回未打印的字符数(或者

任何有用的东西)..我也没有设置errno。但是它应该可以帮助你看到省略号的目的。


希望这会有所帮助,

--Tim


Dear All!

While looking for the implementation of the printf function, I came
across the implementation
that used the following construct

int printf(const char *format, ...)

What is the meaning of "..."? I didn''t find it in K&R book, and
looking for "..." on the web doesn''t seem to be productive. The actual
implementation of the function is a working piece of code,
I managed to compile it successfully.
Is it the way of introducing the generic programming paradigm within
the C language?

Thanks.

解决方案

eotcl wrote:

Dear All!

While looking for the implementation of the printf function, I came
across the implementation
that used the following construct

int printf(const char *format, ...)

What is the meaning of "..."? I didn''t find it in K&R book, and
looking for "..." on the web doesn''t seem to be productive.

Does searching for "ellipsis C" give better results?

e.g. http://en.wikipedia.org/wiki/Ellipsis#In_programming

That should lead you to ''variadic functions''

e.g.
http://en.wikipedia.org/wiki/Variadi...-C_and_C.2B.2B

The actual
implementation of the function is a working piece of code,
I managed to compile it successfully.
Is it the way of introducing the generic programming paradigm within
the C language?

Thanks.

Bye, Jojo


eotcl wrote, On 29/09/08 18:01:

Dear All!

While looking for the implementation of the printf function, I came
across the implementation
that used the following construct

int printf(const char *format, ...)

What is the meaning of "..."? I didn''t find it in K&R book, and

You need to improve your skills at looking things up...

Either that or you need to get the 2nd edition of K&R since it is one of
the "new" features introduced in 1989 or earlier. Don''t throw away your
first edition copy though, it might be worth something ;-)

The index of my copy of K&R2 tells me to look on pages 155 and 202, and
I think the first of these two pages is the easier to learn from.

looking for "..." on the web doesn''t seem to be productive. The actual

Try searching for "variable argument list" or "variable-length argument
lists" or the like, probably including the quotes. Be aware though that
a lot of what is on the web is wrong, often in ways you won''t spot.
However, the comp.lang.c FAQ at http://c-faq.com/ is better than average

implementation of the function is a working piece of code,
I managed to compile it successfully.

That is a strange thing to be doing. Your implementation shoud come with
an implementation of printf that you can use!

Is it the way of introducing the generic programming paradigm within
the C language?

Generic programming in C is a far larger topic than ..., including the
use of macros and void* pointers.
--
Flash Gordon
If spamming me sent it to sm**@spam.causeway.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/


On Sep 30, 1:01 am, eotcl <eotc...@gmail.comwrote:

Dear All!

While looking for the implementation of the printf function, I came
across the implementation
that used the following construct

int printf(const char *format, ...)

What is the meaning of "..."? I didn''t find it in K&R book, and
looking for "..." on the web doesn''t seem to be productive. The actual
implementation of the function is a working piece of code,
I managed to compile it successfully.
Is it the way of introducing the generic programming paradigm within
the C language?

Thanks.

In very lay terms, "..." means arguments that complement format.

For instance, this very simple function :

void psycho_printf(const char *format, ...)
{
va_list ap;

fprintf(stderr, "Charles Manson says: ");
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
fprintf(stderr, "\n");

return;
}

This could be called like:

psycho_printf("%s %s %d", foo, bar, intfoo);

Or:

psycho_printf("%s", foo);

As you can see, the ellipsis allows for an undetermined amount of
arguments. The printf core in a C library is a corner case. My example
is bad, I don''t return the number of characters not printed (or
anything useful) .. nor do I set errno. However it should help you see
the purpose of an ellipsis.

Hope this helps,
--Tim


这篇关于功能定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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