Re:Using Zig's translate-C to understand weird C code
by userbinator on Wednesday November 03, 2021 @09:44AM
(#29094444)
The summary is "array and function has higher precedence than pointer, and parentheses override all". This explains why
is a function returning pointer to int, while
is a pointer to function returning int. Likewise,
is an array of pointer to int, while
is a pointer to array of int.
[ Parent
| on HN ]
Re:Using Zig's translate-C to understand weird C code
by nicoburns on Thursday November 04, 2021 @06:25AM
(#29105345)
Argh! All of these examples seem backwards to me. Why on earth isn't "a pointer to an array of int" something like:
*(int[])
Re:Using Zig's translate-C to understand weird C code
by userbinator on Thursday November 04, 2021 @03:36PM
(#29111587)
Because of how precedence works --- you start from the inside and work outwards, the same as when evaluating ordinary maths expressions.
"Pointer to array of int" means you dereference it first to get an array of ints, then index to get an int.