问题描述
参照的问题Where在声明中可以存储类说明放在哪里? 我开始分析声明,说明符
的概念和声明符
。以下是我的理解积累。
With reference to the question Where in a declaration may a storage class specifier be placed? I started analyzing the concept of declaration-specifiers
and declarators
. Following is the accumulation of my understanding.
- 一般来说,
C
声明遵循声明-符说明符的语法;
-
声明-符
包括的类型提示符
,存储类说明符
和键入限定符
-
声明符
可以是变量,指针,函数和数组等。
- Generally, the
C
declarations follow the syntax ofdeclaration-specifiers declarators;
declaration-specifiers
comprises oftype-specifiers
,storage-class-specifiers
andtype-qualifiers
declarators
can be variables,pointers,functions and arrays etc..
-
声明-符
可以按任何顺序指定,作为一个例子 - 不可能有比单一
存储类说明符更多
- 在另一方面,可以有多个
键入限定符
-
存储类说明符
不得与去声明符
declaration-specifiers
can be specified in any order, as an example- There cannot be more than a single
storage-class-specifier
- On the other hand there can be multiple
type-qualifiers
storage-class-specifier
shall not go with thedeclarator
Q1:在一个常量指针的声明,我看声明符
和类型限定符
的组合作为以下
Q1: In the declaration of a constant pointer, I see a mix of declarator
and type-qualifier
as below
const int *const ptr; //Need justification for the mix of declarator and type-specifier
Q2:可以有一个指向静态INT
。有没有提供指针静态
存储类的可能?意味着指针是静态的。
Q2: There can be a pointer to static int
. Is there a possibility of providing the pointer a static
storage class? Means the pointer being static.
推荐答案
我不知道我完全理解你的第一个问题。在C ++语法03 而言常量
是 CV-预选赛
。 CV-预选赛
可以在 present DECL说明符-SEQ
(如特定种类的<$ C ,以及在 $ C>类型说明符
),这是该声明的共同的一部分初始化声明符列表,其中是一个以逗号分隔各个声明符序列。
I'm not sure I full understand you first question. In terms of C++03 grammar const
is a cv-qualifier
. cv-qualifier
can be present in decl-specifier-seq
(as a specific kind of type-specifier
), which is a "common" part of the declaration, as well as in init-declarator-list
, which is a comma-separated sequence of individual declarators.
语法是专门制定了属于个人的指针声明符一个常量
说明符必须的跟踪的的 *
。 A 常量
说明符precedes首 *
不考虑个人声明符的一部分。这意味着,在本实施例
The grammar is specifically formulated that a const
specifier belonging to an individual pointer declarator must follow the *
. A const
specifier that precedes the first *
is not considered a part of the individual declarator. This means that in this example
int const *a, *b;
常量
属于左侧: DECL说明符-SEQ
,的共同的一部分声明。即无论 A
和 B
声明为 INT常量*
。同时此
const
belongs to the left-hand side: decl-specifier-seq
, the "common" part of the declaration. I.e. both a
and b
are declared as int const *
. Meanwhile this
int *a, const *b;
简直是病态的,并不会编译。
is simply ill-formed and won't compile.
您的第二个问题看起来并不清楚,我不是。看来你得到它倒退。你声称可以有一个指向静态INT
?没有,有没有办法来声明这样的事情指针静态INT
。您可以将静态指针申报 INT
虽然
Your second question doesn't look clear to me either. It seems that you got it backwards. You claim that "there can be a pointer to static int
"? No, there's no way to declare such thing as "pointer to static int
". You can declare a static pointer to int
though
static int *p;
在这种情况下,指针本身是静态的,因为你希望它是。
In this case the pointer itself is static, as you wanted it to be.
这篇关于声明说明符和声明符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!