什么像&QUOT括号的typedef;的typedef INT(F)(无效)QUOT;意思?它是一个函数原型? [英] What does a typedef with parenthesis like "typedef int (f)(void)" mean? Is it a function prototype?

查看:158
本文介绍了什么像&QUOT括号的typedef;的typedef INT(F)(无效)QUOT;意思?它是一个函数原型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

typedef int (fc_name) (void);

下面 fc_name 是任何有效的C标志。

Here fc_name is any valid C symbol.

如何从不同的函数指针是这样的的typedef

How different is this from a function pointer typedef?

推荐答案

这是一个的typedef 函数类型。其目的是将其用于函数指针,但在这种情况下,语法使用将是:

It's a typedef to a function type. The intent is to use it for function pointers, but in this case the syntax to use it would be:

int bar(void);

fc_name* foo = bar; /* Note the * */

更新:
正如评论乔纳森莱弗勒的回答提到的,的typedef CAN用于声明功能。一个用途可能是宣布了一组回调函数:

Update: As mentioned in the comments to Jonathan Leffler's answer, the typedef can be used to declare functions. One use could be for declaring a set of callback functions:

typedef int (callback)(int, void*);

callback onFoo;
callback onBar;
callback onBaz;
callback onQux;

这篇关于什么像&QUOT括号的typedef;的typedef INT(F)(无效)QUOT;意思?它是一个函数原型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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