2017_11_06-const_in_cpp
来源:互联网 发布:百度推广怎么优化账户 编辑:程序博客网 时间:2024/06/05 20:22
const pointer
乔俊峰 Junfeng Qiao, 2017-11-06
最近看到了一篇很好的文章,终于搞清楚了const的用法。
现将重点摘抄如下:
Every declaration in C and C++ has two
principal parts: a sequence of zero or more
declaration specifiers, and a sequence of
one or more declarators, separated by
commas.static unsigned long int *x[N];
declaration specifiers:
static unsigned long int
declarator:
*x[N];
注意
*
是declaratorThe operators in a declarator group according
to the same precedence as they do when
they appear in an expression.所以
[N]
先与x
结合,再与*
结合,x
is an “array of N elements of
pointer to …” somethingParentheses serve two roles in
declarators: first, as the function call
operator, and second, as grouping. As
the function call operator, ()have the
same precedence as []. As grouping,
() have the highest precedence of all.*f(int)
is a declarator
specifying thatf
is a “function …
returning a pointer … .” In contrast,(*f)(int)
specifies thatf
is a “pointer
to a function … .”A declarator may contain more
than one identifier. The declarator*x[N]
contains two identifiers,x
andN
.
Only one of those identifiers is the
one being declared, and it’s called the
declarator-id. The other(s), if any,
must have been declared previously.x
is declarator-idType specifiers contribute to the type of the
declarator-id; other specifiers provide nontype
information that applies directly to the
declarator-id.static unsigned long int *x[N];
unsigned long int
is type specifiers.The keywords
const
andvolatile
are
type specifiers.The order in which the declaration specifiers
appear in a declaration doesn’t matter.The only declaration specifiers that can also
appear in declarators areconst
andvolatile
.pointer declarations read from right-to-left.
Always write const and volatile to the right.T const *p;
T *const p;
Recognizing the boundary between
the last declaration specifier and the
declarator is one of the keys to understanding
declarations.Use
const int *p;
rather thanconst int* p;
文章地址:
http://www.dansaks.com/articles/1999-02%20const%20T%20vs%20T%20const.pdf
- 2017_11_06-const_in_cpp
- 2014_11_06 Topic:Improved Iterative Scaling
- 2011_11_06程序员的修炼之道:从小工到专家
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- VB 学习整理4
- 机器人操作系统
- fatal error: caffe/proto/caffe.pb.h: No such file or directory
- permgen space tomcat
- failed to resolve: com.android.support:appcompat-v7:25.4.0
- 2017_11_06-const_in_cpp
- SpringMVC加载配置Properties文件的几种方式
- Aspose.Pdf11月新版 V17.11发布 | 支持免费下载
- linux 磁盘空间使用查看
- 机房存在哪些安全隐患?需要排查哪些地方?
- 为什么浏览器User-agent总是有Mozilla字样
- 2017.11.6笔记
- Spring Boot 整合 log4j 实现日志管理
- 同步机制的几种实现简介