惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
Project Zero
Project Zero
K
Kaspersky official blog
G
Google Developers Blog
T
Threat Research - Cisco Blogs
T
The Blog of Author Tim Ferriss
Cyberwarzone
Cyberwarzone
Y
Y Combinator Blog
Recorded Future
Recorded Future
Blog — PlanetScale
Blog — PlanetScale
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cisco Talos Blog
Cisco Talos Blog
Latest news
Latest news
Microsoft Security Blog
Microsoft Security Blog
H
Help Net Security
S
Schneier on Security
P
Palo Alto Networks Blog
H
Hacker News: Front Page
N
News and Events Feed by Topic
N
Netflix TechBlog - Medium
博客园 - Franky
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
SecWiki News
SecWiki News
Cloudbric
Cloudbric
TaoSecurity Blog
TaoSecurity Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The Hacker News
The Hacker News
C
Check Point Blog
L
LangChain Blog
腾讯CDC
小众软件
小众软件
T
Tenable Blog
Google DeepMind News
Google DeepMind News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
About on SuperTechFans
Google Online Security Blog
Google Online Security Blog
C
Cisco Blogs
Recent Announcements
Recent Announcements
Hacker News: Ask HN
Hacker News: Ask HN
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Vercel News
Vercel News
雷峰网
雷峰网
美团技术团队
D
DataBreaches.Net
Martin Fowler
Martin Fowler
Help Net Security
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Full Disclosure
博客园_首页

RealCat

📝笔记:图像匹配挑战赛回顾(CVPR 2023) | RealCat 📝笔记:Stable Diffusion QR-Code | RealCat 📝笔记:Python zip() | RealCat 📝笔记:图像匹配挑战赛回顾(CVPR 2022) | RealCat 📝笔记:5秒钟训练NeRF,NVIDIA Instant NeRF 测试 | RealCat 📝笔记:Visualization Localization Revisited(under construction...) | RealCat 📝笔记:使用vlfeat的Matlab接口简单实现BOW以及VLAD | RealCat 📝笔记:一些关于KD-Tree的知识点 | RealCat 📝笔记:简明矩阵求导术之分子布局与分母布局 | RealCat 🔨工具:优雅地下载Youtube视频 | RealCat 🔨工具:每日自动获取arXiv论文摘要 | RealCat 🎃资料: 从Eigen向量化谈内存对齐 | RealCat 📝笔记:图像匹配挑战赛总结 (SuperPoint + SuperGlue 缝缝补补还能再战一年) | RealCat 📝笔记:ICCV 2021最佳学生论文 | COLMAP 优化建图组件 Pixel-Perfect SFM | RealCat 📝笔记:CVPR 2021 | PixLoc: 端到端场景无关视觉定位算法(SuperGlue一作出品) | RealCat 📝笔记:港大MARS实验室 R3LIVE (R2LIVE升级) 鲁棒实时RGB雷达视觉惯导紧耦合状态估计 | RealCat 🔨工具:bash常用命令 | RealCat 📝笔记:VSLAM基础知识导图 | RealCat 📝笔记:Patch-NetVLAD论文阅读 | RealCat 📝笔记:光场相机能否用于SLAM? | RealCat 📝笔记:读写文本常用操作 | RealCat 📝笔记:CVPR 2020 视觉定位挑战赛冠军方案 | RealCat 📝笔记:三维重建系列 COLMAP: Structure-from-Motion Revisited | RealCat 🐈芒果驾到 | RealCat 📝笔记:GMS一种基于运动统计的快速鲁棒特征匹配过滤算法 | RealCat 🌡️秋天到了,还是很热 | RealCat 📝笔记:AdaLAM: Revisiting Handcrafted Outlier Detection 超强外点滤除算法 | RealCat 🔨工具:使用vercel加速Hexo静态博客访问 | RealCat 📝笔记:ORB-SLAM3论文阅读 | RealCat 🔨工具:解决Github挂图及龟速访问 | RealCat 📝笔记:图解卡尔曼滤波 | RealCat 🔨工具:国内加速访问arxiv | RealCat 📝笔记:CVPR2020图像匹配挑战赛,新数据集+新评测方法,SOTA正瑟瑟发抖! | RealCat 📝笔记:SuperGlue:Learning Feature Matching with Graph Neural Networks论文阅读 | RealCat 📝笔记:SLAM常见问题(四):求解ICP,利用SVD分解得到旋转矩阵 | RealCat 📝笔记:SLAM常见问题(五):Singular Value Decomposition(SVD)分解 | RealCat 📝笔记:SLAM常见问题(三):PNP | RealCat 📝笔记:SLAM常见问题(二):重定位Relocalisation | RealCat 📝笔记:SLAM常见问题(一):SearchByBoW | RealCat 📝笔记:2019年浙大CADCG暑假SLAM培训部分课件 | RealCat 🔨工具:Filebrowser:一款轻量级个人网盘 | RealCat 📝笔记:SuperPoint: Self-Supervised Interest Point Detection and Description 自监督深度学习特征点 | RealCat Black Hole | RealCat 🔥Awesome CV Works | RealCat 🔨工具:开启SSR模式 | RealCat 虚实:「未麻的部屋」 | RealCat 笔记:李群与李代数求导 | RealCat 资料:ORB SLAM2 阅读报告 | RealCat 资料:SLAM草稿 | RealCat 资料:Line Segments Detection | RealCat 资料:Eigen与Matlab语句之对应关系 | RealCat 笔记:清华-谷歌人工智能研讨会(Tsinghua-Google AI Symposium) | RealCat Think Different | RealCat Light Field Depth Estimation | RealCat CV Related References | RealCat 立体视觉综述:Stereo Vision Overview | RealCat Lytro的光场AR之路:从巅峰到死亡 | RealCat Stephen Hawking | RealCat 常用的生产力工具 | RealCat 深度学习在深度(视差)估计中的应用(2) | RealCat 深度学习在深度(视差)估计中的应用(1) | RealCat Matlab Deep Learning学习笔记 | RealCat CNN框架(CNN Architectures) | RealCat 理解LSTM网络【译】 | RealCat 降维之PCA主成分分析原理 | RealCat 📝笔记:SIFT和SURF特性提取总结 | RealCat 统计学习方法总结 | RealCat Ubuntu上使用Git以及GitHub | RealCat 机器学习修炼手册 | RealCat 初试HCI光场数据集 | RealCat 实习季到了,大家又浮躁了起来 | RealCat 日本与美国之行 | RealCat Light Field 光场以及MATLAB光场工具包(LightField ToolBox)的使用说明 | RealCat MATLAB:多个不同维度的箱线图画在一起 | RealCat AR形势与应用 | RealCat Hexo+Github+jsDelivr+Vercel建站备忘录 | RealCat Markdown 学习 | RealCat 复试那些事儿 | RealCat
📝笔记:使用Clockwise/Spiral Rule技巧轻松读懂变量/函数声明 | RealCat
2022-02-28 · via RealCat

本文介绍一种让编程者很方便搞清楚C/C++变量或者函数声明的小技巧Clockwise/Spiral Rule,本文很大部分内容参考自David Anderson于1994年05月06日写的一篇博客

规则

Step 1. 从未知的变量开始,以“螺旋状+顺时针”方向移动,当遇到以下内容时,请用相应的英文语句来代替它们:

[X] or []
=> Array X size of... or Array undefined size of...

(type1, type2)
=> function passing type1 and type2 returning...

*
=> pointer(s) to...

Step 2. 重复步骤1,直到所有的符号都被遍历; Step 3. 一定要先解决括号里的东西!

例1: 简单声明

     +-------+
     | +-+   |
     | ^ |   |
char *str[10];
 ^   ^   |   |
 |   +---+   |
 +-----------+

首先问自己的一个问题:str是什么玩意? > str is an …

  • 我们从str开始,以螺旋式顺时针方向移动,我们看到的第一个字符是[,所以,这意味着这里有一个数组,所以… > str is an array 10 of…

  • 继续以螺旋式的顺时针方向前进,我们遇到的下一符号是*,所以,这意味着这里有个指针,所以… > str is an array 10 of pointers to…

  • 继续沿螺旋方向前进,我们看到了行的末端(;),所以继续前进,得到了char类型,所以… > str is an array 10 of pointers to char

  • 现在已经访问了每一个符号,搞定!

例2: 指向函数声明的指针

     +--------------------+
     | +---+              |
     | |+-+|              |
     | |^ ||              |
char *(*fp)( int, float *);
 ^   ^ ^  ||              |
 |   | +--+|              |
 |   +-----+              |
 +------------------------+

首先问自己的一个问题:fp是什么玩意? > fp is a …

  • 我们从fp开始,以螺旋式顺时针方向移动,我们看到的第一个字符是),因此fp在括号内,所以我们在括号内继续螺旋式移动,看到的下一个字符是*,所以… > fp is a pointer to…

  • 我们离开了小括号,继续以螺旋式顺时针方向前进,我们看到了(;因此,我们有一个函数,所以… > fp is a pointer to a function passing an int and a pointer to float returning…

  • 继续以螺旋方式进行,然后我们看到 * 字符,所以… > fp is a pointer to a function passing an int and a pointer to float returning a pointer to

  • 以螺旋的方式继续,我们看到了;,但还没有访问所有的符号,所以继续,最后到了char类型,所以… > fp is a pointer to a function passing an int and a pointer to float returning a pointer to char

  • 现在已经访问了每一个符号,搞定!

例3: 终极挑战!

      +-----------------------------+
      |                  +---+      |
      |  +---+           |+-+|      |
      |  ^   |           |^ ||      |
void (*signal(int, void (*fp)(int)))(int);
 ^    ^      |      ^    ^  ||      |
 |    +------+      |    +--+|      |
 |                  +--------+      |
 +----------------------------------+

首先问自己的一个问题:signal是什么玩意? (注意,变量signal在括号内,所以我们必须先搞定它) > signal is a …

  • 沿着顺时针方向移动,我们看到(,所以我们有… > signal is a function passing an int and a …

  • 额,函数传参的第二个变量有点复杂;那我们可以对fp使用同样的规则,所以…fp是什么玩意?fp也在小括号内,所以继续我们看到一个*,所以… > fp is a pointer to…

  • 继续沿顺时针方向螺旋上升,我们得到了(,所以知道遇到了函数… > fp is a pointer to a function passing int returning…

  • 现在继续走出函数的小括号,我们看到了void,所以… > fp is a pointer to a function passing int returning nothing(void)

  • 我们已经完成了解析fp,所以让我们继续解析signal,我们现在有… > signal is a function passing an int and a pointer to a function passing int returning nothing(void)

  • 注意到我们仍然在括号内,所以看到的下一个字符是 *,所以… > signal is a function passing an int and a pointer to a function passing int returning nothing returning a pointer to…

  • 我们现在已经解决了括号内的符号,所以继续按顺时针方向,我们看到另一个(,我们知道遇到了函数,所以… > signal is a function passing an int and a pointer to a function passing int returning nothing returning a pointer to a function passing int returning…

  • 最后我们继续,唯一剩下的就是void,所以signal的最终完整定义是… > signal is a function passing an int and a pointer to a function passing int returning nothing returning a pointer to a function passing int returning nothing(void)

  • 现在已经访问了每一个符号,搞定! d ## 其它

这个规则同样适用于const 以及 volatile,例如:

const char *ptr;

ptr is a pointer to a char constant (ptr 是指向 const char 的指针,即ptr指向的值不可改变,但是指针可以改变)

char const *ptr;

ptr is a pointer to a constant char

所以 const char *ptrchar const * ptr表示一个意思。

char * const ptr;

ptr is a constant pointer to char (ptr 是一个const指针指向char,即ptr不可改变,但是指针指向的内容可以改变)

volatile char * const ptr;

ptr is a constant pointer to char volatile

参考

  1. David Anderson, Clockwise/Spiral Rule, http://c-faq.com/decl/spiral.anderson.html, 1994.
  2. stackoverflow, What is the difference between const int*, const int* const, and int const *?