2013-07-19 56 views
0

关于声明;声明符是否有零声明说明符?

Every object 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. For example:
enter image description here

是否零符意味着声明名为a作为

a; 

,而不是

int a; 

变量? 我试图用一个例子

#include <stdio.h> 

int main(){ 
    x = 9; 
    printf("%d\n", x); 

return 0; 
} 

,这是给了一个错误:

[Error] 'x' undeclared (first use in this function) 
+3

你是从哪里得到的?这显然是错误的。 –

+1

对于具有“隐式诠释规则”的预标准化C可能是正确的。无论如何,这应该永远不会被使用。 –

+0

@CarlNorum;我从[这里]得到了这个(https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&cad=rja&ved=0CEYQFjAD&url=http%3A%2F%2Fwww.dansaks。 COM%2Farticles%2F1998-06%2520Placing%2520const%2520in%2520Declarations.pdf&= rXrpUbKnAcrMrQfUjoCQBQ&USG = AFQjCNG8M1tyIyLS1jJ-bX5MXZ-TcjgYQg&SIG2 = 5pdYOyGUhbjWUp32yxLQvg&BVM = bv.49478099,d.bmk) – haccks

回答

2

这是可能的C89与隐int规则,但你至少需要限定符或存储类说明符。

auto x = 3; /* allowed in c89, not valid in c99 */ 

static y = 4; /* allowed in c89, not valid in c99 */ 

const z = 5; /* allowed in c89 , not valid in c99*/ 

a;  /* not valid in c89, c99 without a prior declaration */ 

b = 6; /* not valid in c89, c99 without a prior declaration */ 
+0

但是,所有的这些声明使用了一个说明符! – haccks

+0

@haccks'const'是限定符而不是说明符。 – ouah

+0

我读过有关修饰符的修饰符,它修改了数据类型的特征,比如它的'size'或'sign' **。关于'signed',它是限定符还是说明符? – haccks

1

无论你从得到了声明,这是错的。您必须至少有一个声明说明符以使声明有效。下面是从标准的相关位(这是一个形象,因为我不能让降价的行为):

C11 standard about declarations

+0

我从[杂志代码片段](https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&cad=rja&ved=0CEYQFjAD&url=http%3A%2F%2Fwww .dansaks.com%2Farticles%2F1998-06%2520Placing%2520const%2520in%2520Declarations.pdf&EI = rXrpUbKnAcrMrQfUjoCQBQ&USG = AFQjCNG8M1tyIyLS1jJ-bX5MXZ-TcjgYQg&SIG2 = 5pdYOyGUhbjWUp32yxLQvg&BVM = bv.49478099,d.bmk)(1998年6月嵌入式系统编程) – haccks