☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

不应采用复杂的声明

6.10.1 ID_complexDeclaration
目录 › next › previous

复杂的声明可读性较差,容易造成理解上的偏差。

对于:

  • 函数指针的数组
  • 返回函数指针、数组指针的函数
  • 以函数指针、数组指针为参数的函数

应先将各子类型取别名,再用简单声明的方式书写。

示例:

int (*foo(int))(bool);   // Bad, returns a function pointer
int (*foo(char))[123];   // Bad, returns an array pointer

例中声明的是两个函数,但看起来像是函数指针,而且参数列表也显得混乱。

应改为:

typedef int(*funptr)(bool);
typedef int(*arrptr)[123];

funptr foo(int);    // Good
arrptr foo(char);   // Good
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.