关于C函数的问题 [英] Question about C Functions

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

问题描述

如果我有这个功能:


int f(int(* h)(int)){

return(* h)(13) ;

}


究竟是什么(int(* h)(int))呢?所以这是一个指针但是

两个整数是什么?谢谢。

If I have the function:

int f(int (*h)(int)) {
return (*h)(13);
}

What exactly does (int (*h)(int)) do? So it''s taking a pointer but
what''s with the two ints? Thanks.

推荐答案

jobo写道:
jobo wrote:

如果我有功能:


int f(int(* h)(int)){

return(* h)(13);

}


究竟是什么(int(* h)(int))呢?所以这是一个指针但是

两个整数是什么?谢谢。
If I have the function:

int f(int (*h)(int)) {
return (*h)(13);
}

What exactly does (int (*h)(int)) do? So it''s taking a pointer but
what''s with the two ints? Thanks.



f是一个返回int的函数。它将一个指针

作为参数返回给返回int的函数,该函数将int作为

参数。 f'的论点叫做h。 f调用h指向的函数

,参数为13.


查找名为cdecl的程序,这有助于解释C

声明。


-

Thomas M. Sommers - tm * @ nj.net - AB2SB

f is a function returning int. It takes as an argument a pointer
to a function returning int, which function takes an int as an
argument. f''s argument is called h. f calls the function
pointed to by h with an argument of 13.

Look for the program called cdecl, which helps explain C
declarations.

--
Thomas M. Sommers -- tm*@nj.net -- AB2SB


jobo写道:
jobo wrote:

如果我有这个功能:


int f(int(* h)(int)){

return(* h)(13);

}


究竟是什么(int(* h)(int))呢?所以这是一个指针但是

两个整数是什么?谢谢。
If I have the function:

int f(int (*h)(int)) {
return (*h)(13);
}

What exactly does (int (*h)(int)) do? So it''s taking a pointer but
what''s with the two ints? Thanks.




增量读作:


h - 一个指针

(* h) - 其解除引用的值

(* h)(int) - 是一个接受单个int作为

参数的函数

int(* h)(int) - 并返回一个int

因此h是一个指向具有上述参数

和返回类型的函数的指针。例如,h可用于指向C标准中定义的''toupper''

函数:

#include< stdio.h>

#include< stdlib.h>

#include< ctype.h>


int main(void)

{

int(* h)(int);

h = toupper;

printf("%c编程很难) !\ n",(* h)(''c''));

返回0;

}


-

希望这会有所帮助,

史蒂文



Incrementally read as:

h -- a pointer
(*h) -- whose dereferenced value
(*h)(int) -- is a function that accepts a single int as a
parameter
int (*h)(int) -- and returns an int
Thus h is a pointer to a function with the aforementioned parameter
and return types. For example, h can be used to point to the ''toupper''
function defined in the C standard:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main (void)
{
int (*h)(int);
h = toupper;
printf ("%c programming is hard!\n", (*h)(''c''));
return 0;
}

--
Hope this helps,
Steven


" jobo" < jo ***** @ gmail.comwrites:
"jobo" <jo*****@gmail.comwrites:

如果我有这个功能:


int f( int(* h)(int)){

返回(* h)(13);

}


究竟是什么(int(* h)(int))吗?所以这是一个指针但是

两个整数是什么?谢谢。
If I have the function:

int f(int (*h)(int)) {
return (*h)(13);
}

What exactly does (int (*h)(int)) do? So it''s taking a pointer but
what''s with the two ints? Thanks.



f是一个返回int类型结果的函数。它有一个类型为int(*)(int)的单个

参数,h。换句话说,h是函数的指针

;该函数有一个int类型的参数,

返回int类型的结果。


有一个名为cdecl的程序这通常对这种

的东西很有用(虽然它不喜欢参数名称):


%cdecl

输入'help''或'?''寻求帮助

cdeclexplain int f(int(* h)(int))

语法错误

cdeclexplain int f(int(*)(int))

将f声明为函数(返回int的函数(int)指针)返回int

cdecl> ;


我是从

< http://www.ibiblio.org/pub/Linux/devel/lang/c/cdecl-2.5获得的.tar.gz>


-

Keith Thompson(The_Other_Keith) ks ***@mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *< http://users.sdsc .edu / ~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。

f is a function that returns a result of type int. It has a single
parameter, "h", of type int (*)(int). In other words, h is a pointer
to a function; that function has a single parameter of type int, and
returns a result of type int.

There''s a program called "cdecl" that''s often helpful for this kind of
thing (though it doesn''t like the parameter name):

% cdecl
Type `help'' or `?'' for help
cdeclexplain int f(int (*h)(int))
syntax error
cdeclexplain int f(int (*)(int))
declare f as function (pointer to function (int) returning int) returning int
cdecl>

I got it from
<http://www.ibiblio.org/pub/Linux/devel/lang/c/cdecl-2.5.tar.gz>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


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

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