4 ms·
Do the parens in `int * (*) []` do anything? When I saw them I immediately assumed that function pointers would be involved, but it doesn't seem to be the case
by simias 5y ago
Do the parens in `int * (*) []` do anything? When I saw them I immediately assumed that function pointers would be involved, but it doesn't seem to be the case and now I'm confused.
EDIT: Uh, apparently you can add parens to casts but not declarations.
This doesn't compile:
int (*) p = (int *)&i;
This does:
int *p = (int (*))&i
I can't quite justify this behaviour.
- MauranKilom 5y agoI think this is just about where the identifier has to go in a declaration. Otherwise the spiral rule [or rather right-left-rule, as pointed out elsethred] doesn't start at the right place (to over-simplify it). You can in fact have parentheses in declarations, but the identifier must be on the inside, not just to the right of everything: https://godbolt.org/z/vKzcYMdvK https://godbolt.org/z/vKzcYMdvK
- foxfluff 5y agoYes they do something. They are used to override precedence, just as you would in a math expression. Array indexing has higher precedence than pointer dereferencing, and declarations follow the same precedence that you have in expressions. int **p[123]; // p is array(123) of pointer to pointer to int int *(*p)[123]; // p is a pointer to array(123) of pointer to int Sometimes people find casts confusing because there is no identifier inside. But you can easily read it if you know where the identifier would be in an equivalent declaration. Precedence is usually documented in a man page called operator. http://man.openbsd.org/operator http://man.openbsd.org/operator