1

Regarding the statement;

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

Does zero specifier means declaring a variable named a as

a;

and not

int a;

? I tried this with an example

#include <stdio.h>

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

return 0; 
}  

and this is giving an error:

[Error] 'x' undeclared (first use in this function) 
haccks
  • 104,019
  • 25
  • 176
  • 264
  • 3
    Where did you get that statement from? It's clearly wrong. – Carl Norum Jul 19 '13 at 17:40
  • 1
    It might have been true for pre-standardization C, which has the "implicit int rule". Regardless, this should never have been used. – R.. GitHub STOP HELPING ICE Jul 19 '13 at 17:41
  • @CarlNorum; I get this from [here](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) – haccks Jul 19 '13 at 17:45
  • Sounds like a pre C89 C, valid then, but with C89 and forward not allowed. Nice that you were ready with the reference. – chux - Reinstate Monica Jul 19 '13 at 18:01

2 Answers2

2

It was possible in c89 with the implicit int rule but you needed at least a qualifer or a storage class specifier.

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 */
ouah
  • 142,963
  • 15
  • 272
  • 331
  • But all of these declaration used an specifier! – haccks Jul 19 '13 at 17:57
  • @haccks `const` is a qualifier not a specifier. – ouah Jul 19 '13 at 17:58
  • I read about qualifiers that **it alters the characteristics of the data type, such as its `size` or `sign`**. What about `signed`, Is it qualifier or specifier? – haccks Jul 19 '13 at 18:07
  • qualifiers do not alter size or sign, you are talking about a type specifier. `signed` is a type specifier. – ouah Jul 19 '13 at 18:09
  • I think this time you are wrong ouah; Read this [answer](http://stackoverflow.com/a/5103836/2455888). – haccks Jul 19 '13 at 18:34
  • 1
    @hackks No, I don't think I'm wrong. Type qualifiers are `const`, `volatile`, `restrict` and `_Atomic`. See c11, 6.7.3 Type qualifiers. – ouah Jul 19 '13 at 18:43
1

Wherever you got that statement from, it's wrong. You have to have at least one declaration-specifier for a declaration to be valid. Here's the relevant bit from the standard (it's an image because I couldn't make markdown behave):

C11 standard about declarations

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
  • I get this from a [magazine snippet](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)(JUNE 1998 EMBEDDED SYSTEMS PROGRAMMING) – haccks Jul 19 '13 at 17:49