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

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

问题描述

如何解读如下声明复杂?

 字符(*(* F())[])();炭(*(* X [3])())[5];无效(* F)(INT,无效(*)());烧焦FAR * FAR * PTR;无效的typedef(* pfun)(整型,浮点);INT **(* F)(INT **,** INT(*)(INT **,** INT));


解决方案

正如其他人所指出的那样,CDECL是这个职位的合适的工具。

如果你想理解那种声明未经CDECL的帮助下,尝试从内到外,右读至左

以从列表中的 字符(*(* X [3])())[5]一个随便举个例子; 的结果
在启动X,这是识别正在申报/定义(和最里面的标识符):

 字符(*(* X [3])())[5];
         ^

X为

  X [3]
 ^^^

X为 的数组3

 (* X [3])
 ^ / *括号组子前pression * /

X是数组3 指针

 (* X [3])()
       ^^

x是3指针数组 函数接受的参数未指定的(但固定)号

 (*(* X [3])())
 ^ / *多个分组括号* /

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

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

X为3个指针数组函数接受的参数未指定的(但固定)号和返回一个指针 组合阵列5

 字符(*(* X [3])())[5];
^^^^ ^

X为3个指针数组函数接受的参数未指定的(但固定)的数量,并返回一个指向5 的数组字符

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 **));

解决方案

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

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

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 is

X[3]
 ^^^

X is an array of 3

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

X is an array of 3 pointers to

(*X[3])()
       ^^

X is an array of 3 pointers to function accepting an unspecified (but fixed) number of arguments

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

X is an array of 3 pointers to function accepting an unspecified (but fixed) number of arguments and returning a pointer

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

X is an array of 3 pointers to function accepting an unspecified (but fixed) number of arguments and returning a pointer to an array of 5

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

X is an array of 3 pointers to function accepting an unspecified (but fixed) number of arguments and returning a pointer to an array of 5 char.

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

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