我如何理解复杂的函数声明? [英] How do I understand complicated function declarations?

查看:24
本文介绍了我如何理解复杂的函数声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何理解以下复杂的声明?

How do I understand following complicated declarations?

char (*(*f())[])();

char (*(*X[3])())[5];

void (*f)(int,void (*)()); 

char far *far *ptr;

typedef void (*pfun)(int,float);

int **(*f)(int**,int**(*)(int **,int **));

推荐答案

正如其他人所指出的,cdecl 是完成这项工作的正确工具.

As others have pointed out, cdecl is the right tool for the job.

如果您想在没有 cdecl 帮助的情况下理解这种声明,请尝试从内到外从右到左阅读

If you want to understand that kind of declaration without help from cdecl, try reading from the inside out and right to left

从你的列表中随机抽取一个例子 char (*(*X[3])())[5];
从 X 开始,它是被声明/定义的标识符(也是最里面的标识符):

Taking one random example from your list char (*(*X[3])())[5];
Start at X, which is the identifier being declared/defined (and the innermost identifier):

char (*(*X[3])())[5];
         ^

X 是

X[3]
 ^^^

X 是 一个 3 的数组

(*X[3])
 ^                /* the parenthesis group the sub-expression */

X 是一个包含 3 个 指向

(*X[3])()
       ^^

X 是一个包含 3 个指针的数组 接受未指定(但固定)数量的参数的函数

(*(*X[3])())
 ^                   /* more grouping parenthesis */

X 是一个由 3 个指向函数的指针组成的数组,该函数接受未指定(但固定)数量的参数 并返回一个指针

(*(*X[3])())[5]
            ^^^

X 是一个包含 3 个函数指针的数组,该函数接受未指定(但固定)数量的参数并返回一个指针 指向 5 个数组

char (*(*X[3])())[5];
^^^^                ^

X 是一个包含 3 个函数指针的数组,该函数接受未指定(但固定)数量的参数并返回一个指向 5 个 char 数组的指针.

这篇关于我如何理解复杂的函数声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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