Question

There is declaration extern int (x)[] at the end of this article. Are the parentheses doing anything or they are just for confusion?

My guess would be that with parentheses x is an array of external integers (and that's what the article says), but without those x would be an external array of integers. If this is true, how would the definitions differ? Wouldn't they both be int x[]?

Was it helpful?

Solution

Nope, the parens are not doing anything there. The article you link to explains why:

The simplest way to differentiate the two is to look at the placement of the type specifiers. If a type specifier immediately follows a left parenthesis, that parenthesis is the start of a function descriptor and the type is part of a function parameter. Empty parentheses also signify a function. Otherwise the parentheses are grouping (perhaps unnecessarily, but it's better to have too many than too few) the expression.

Also note that "array of external ints" and "external array of ints" are the exact same thing -- the "extern-ness" always goes to the object being declared, which in this case is an array. Personally I think the first way to describe it is technically inaccurate and simply confusing.

OTHER TIPS

The paranthesis are of no significance in that case. Normally, you use paranthesis for either function-pointers or to mark stronger binding, as all Operators have a different Level of binding.
The extern keyword marks, that this is just a declaration, but the actual definition of this array will happen somwhere else.

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