Question

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) 
Was it helpful?

Solution

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 */

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top