Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #162527
| From | Kaz Kylheku <563-365-8930@kylheku.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: int(*const parse_packet)(const char *, size_t, char **); |
| Date | 2021-09-01 05:07 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <20210831215224.823@kylheku.com> (permalink) |
| References | <83c10100-bedf-47eb-b595-7a8db983ac51n@googlegroups.com> <sgm5pd$u9g$1@dont-email.me> |
On 2021-08-31, John Bode <jfbode1029@gmail.com> wrote:
> On 8/31/21 5:35 AM, hongy...@gmail.com wrote:
>> See the following c code snippet located at here [1]:
>>
>> typedef struct protocol {
>> const int default_port;
>> int(*const parse_packet)(const char *, size_t, char **);
>> } protocol_t;
>>
>> In the above definition, it seems to me that the `int ...' line is difficult to understand. Any hints will be highly appreciated.
>>
>> [1] https://github.com/hongyi-zhao/shadowsocksr-libev/blob/1be671bd5fe7cd55d3823d4669786c9ba7913b9e/src/protocol.h#L29
>>
>> Regards,
>> HY
>>
>
> When reading complex declarations, start by finding the leftmost
> identifier and work your way out, remembering the following rules:
When reading complex declarators, first consider any precedence
parentheses. Read these inside out.
Within every parenthesized grouping, consider what are the postfix type
constructors on the right, and the unary type constructors on the left.
The postfix constructors all have a higher precedence. All operators
proceed away from the thing being declared: postfix are
left-associative, unary are right-associative.
If there are no such parentheses, there is only one grouping.
E.g.
(* ( **a[3][4] ) (int) )
^ ^ ^ ^
| ` inner par `
` '
` outer par ---------'
We start within the inner parens. The postix type constructor operators
are [3][4] and they apply in that order:
a is an array of 3 elements, which are arrays of 4
Having dealt with postfix, we look at the lower-precedence unaries,
which indicate what a is an array of. There are two stars, so pointer to
pointer:
a is an array of 3 elements, which are arrays of 4
... pointers to pointer
OK, we are done at this parenthesis level; we take the elevator
out one floor. The only postfix operator there is the function parameter
list declarator syntax (int):
a is an array of 3 elements, which are arrays of 4
... pointers to pointer
... to a function that takes an int parameter, returning ...
Then we look at the unary: what the function returns:
a is an array of 3 elements, which are arrays of 4
... pointers to pointer
... to a function that takes an int parameter, returning
... a pointer
We are now done with the declarator. We must look at the declaration
specifiers. For instance, if those are "struct foo".
a is an array of 4 arrays of 3
... pointers to pointer
... to a function that takes an int parameter, returning
... a pointer
... to struct foo
The parentheses in a declarator prevent all of its postfix operators
from applying before all of its unaries; they are necessary precisely
when the type we are constructing is a sequence of constructions that
requires a mixing of unary and postfix type construction operators.
--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
int(*const parse_packet)(const char *, size_t, char **); "hongy...@gmail.com" <hongyi.zhao@gmail.com> - 2021-08-31 03:35 -0700
Re: int(*const parse_packet)(const char *, size_t, char **); Bonita Montero <Bonita.Montero@gmail.com> - 2021-08-31 12:59 +0200
Re: int(*const parse_packet)(const char *, size_t, char **); "hongy...@gmail.com" <hongyi.zhao@gmail.com> - 2021-08-31 06:07 -0700
Re: int(*const parse_packet)(const char *, size_t, char **); Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-08-31 08:01 -0700
Re: int(*const parse_packet)(const char *, size_t, char **); Manfred <noname@add.invalid> - 2021-08-31 15:01 +0200
Re: int(*const parse_packet)(const char *, size_t, char **); John Bode <jfbode1029@gmail.com> - 2021-08-31 16:08 -0500
Re: int(*const parse_packet)(const char *, size_t, char **); "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-08-31 14:32 -0700
Re: int(*const parse_packet)(const char *, size_t, char **); Bart <bc@freeuk.com> - 2021-08-31 22:39 +0100
Re: int(*const parse_packet)(const char *, size_t, char **); "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-09-01 14:40 -0700
Re: int(*const parse_packet)(const char *, size_t, char **); "hongy...@gmail.com" <hongyi.zhao@gmail.com> - 2021-08-31 18:21 -0700
Re: int(*const parse_packet)(const char *, size_t, char **); Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-08-31 19:54 -0700
Re: int(*const parse_packet)(const char *, size_t, char **); Kaz Kylheku <563-365-8930@kylheku.com> - 2021-09-01 05:07 +0000
Re: int(*const parse_packet)(const char *, size_t, char **); "hongy...@gmail.com" <hongyi.zhao@gmail.com> - 2021-08-31 23:19 -0700
Re: int(*const parse_packet)(const char *, size_t, char **); James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-09-01 10:34 -0400
Re: int(*const parse_packet)(const char *, size_t, char **); Bart <bc@freeuk.com> - 2021-09-01 16:22 +0100
Re: int(*const parse_packet)(const char *, size_t, char **); "hongy...@gmail.com" <hongyi.zhao@gmail.com> - 2021-09-01 20:02 -0700
Re: int(*const parse_packet)(const char *, size_t, char **); Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-09-01 21:01 -0700
Re: int(*const parse_packet)(const char *, size_t, char **); "hongy...@gmail.com" <hongyi.zhao@gmail.com> - 2021-09-01 23:18 -0700
Re: int(*const parse_packet)(const char *, size_t, char **); scott@slp53.sl.home (Scott Lurndal) - 2021-09-02 15:02 +0000
Re: int(*const parse_packet)(const char *, size_t, char **); Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-09-02 15:24 +0000
Re: int(*const parse_packet)(const char *, size_t, char **); Bart <bc@freeuk.com> - 2021-09-02 10:40 +0100
Re: int(*const parse_packet)(const char *, size_t, char **); Paul N <gw7rib@aol.com> - 2021-09-01 08:32 -0700
csiph-web