Is [ ] also a declarator (when used in parameter declaration) in C?
Asked Answered
T

1

2

6.7.6 Declarators says

Each declarator declares one identifier, and asserts that when an operand of the same form as the declarator appears in an expression, it designates a function or object with the scope, storage duration, and type indicated by the declaration specifiers.

And also states about syntax of parameter:

parameter-declaration:
    declaration-specifiers declarator
    declaration-specifiers abstract-declarator(opt)

For the given function prototype

int f( int a[], int n); 

int a[] declares a parameter with declarator a[] which declares an identifier a.


While in case of

int f( int [], int n);

int [] declares parameter is an array of int with no identifier.
Is [] also a declarator ? ( I think no because it doesn't declare an identifier but syntax for parameter says it is!)

Toner answered 22/7, 2013 at 17:34 Comment(4)
Each declarator declares one identifier. [] is an abstract declarator.Colton
@n.m.; What is an abstract declarator? I was jus thinking about that!Toner
@n.m.; Thanks. Here it is.Toner
You have quoted a production that mentions it. The definition should be somewhere around 6.7.7 I guess.Colton
C
6

In the identifier-less parameter declaration, you have an abstract declarator. That is, the [] in int f(int [], int n) is an abstract declarator for the array. You can find more in sections §6.7.6 Declarators and §6.7.7 Type names in ISO/IEC 9899:2011 (the C11 standard).

Canaday answered 22/7, 2013 at 18:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.