问题描述
无效的typedef int_void(INT);
int_void
是函数将整数和返回什么。
我的问题是:能不能用独,没有一个指针也就是说,是否有可能将其作为简单的 int_void
而不是 int_void *
?
无效的typedef int_void(INT);
int_void试验;
这code编译。但测试
以某种方式使用或分配的东西(没有投)?
/ *即使这不起作用(错误:函数分配)* /
无效的typedef int_void(INT);
int_void测试,测试2;
测试= TEST2;
什么情况是,你得到的功能更短的声明。
您可以致电测试
,但你需要一个实际的测试()
功能。
,因为它是一个标签,本质上是一个恒定值不能分配任何测试。
您也可以使用 int_void
来定义一个函数指针作为尼尔显示。
示例
无效的typedef int_void(INT);诠释的main()
{
int_void试验; / *转发测试的声明,相当于:
*无效测试(INT); * /
试验(5);
}无效测试(INT ABC)
{
}
typedef void int_void(int);
int_void
is a function taking an integer and returning nothing.
My question is: can it be used "alone", without a pointer? That is, is it possible to use it as simply int_void
and not int_void*
?
typedef void int_void(int);
int_void test;
This code compiles. But can test
be somehow used or assigned to something (without a cast)?
/* Even this does not work (error: assignment of function) */
typedef void int_void(int);
int_void test, test2;
test = test2;
What happens is that you get a shorter declaration for functions.
You can call test
, but you will need an actual test()
function.
You cannot assign anything to test because it is a label, essentially a constant value.
You can also use int_void
to define a function pointer as Neil shows.
Example
typedef void int_void(int);
int main()
{
int_void test; /* Forward declaration of test, equivalent to:
* void test(int); */
test(5);
}
void test(int abc)
{
}
这篇关于Typedeffing功能(不是函数指针)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!