关于typedef声明与定义一个新类型的问题

NeilHappy 2012-12-22 01:02:32
typedef void * func_thread(void *); //定义一个函数类型func_thread,该函数类型的参数是void*,返回值是void*
func_thread print_count; //声明一个func_thread类型的函数。该函数print_count的参数是void *,返回值是void*
当我要定义这个print_count函数的时候,还是必须写成 void* print_count(void *p)吗?可以再用func_thread这个定义的函数类型吗吗?
...全文
124 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
NeilHappy 2012-12-22
  • 打赏
  • 举报
回复
引用 1 楼 lile1234_show 的回复:
C/C++ code?12345678910111213typedef void (*func_thread)(void *); func_thread print_count; void testFunc(void *p){ printf("%s",p);};int main(){ print_count = testFunc; char* s……
这样与直接定义print_count没有什么区别吧,仅仅是把print_count当作一个指针在用了,但还是得用这样void *testFunc(void *p)复杂的定义方式。
lee_鹿游原 2012-12-22
  • 打赏
  • 举报
回复

typedef void (*func_thread)(void *); 
func_thread print_count; 
void testFunc(void *p)
{
	printf("%s",p);
};
int main()
{	
	print_count = testFunc;
	char* str = "callback";
	print_count(str);
	return 0;
}

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧