Skupiny Google už nepodporují nová předplatná ani příspěvky Usenet. Historický obsah lze zobrazit stále.

Query the data structure definition of c from the *nix man page.

19 zobrazení
Přeskočit na první nepřečtenou zprávu

hongy...@gmail.com

nepřečteno,
31. 8. 2021 6:33:5331.08.21
komu:
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. So I want to dig/find some clues from the extensive/exhaustive *nix man page. I'm not sure if there is a convenient way to do this.

Any hints will be highly appreciated.

[1] https://github.com/hongyi-zhao/shadowsocksr-libev/blob/1be671bd5fe7cd55d3823d4669786c9ba7913b9e/src/protocol.h#L29

Regards,
HY

Janis Papanagnou

nepřečteno,
31. 8. 2021 6:41:1931.08.21
komu:
On 31.08.2021 12:33, 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. So I want to dig/find some clues from the extensive/exhaustive *nix man page. I'm not sure if there is a convenient way to do this.
>
> Any hints will be highly appreciated.

Get a C language tutorial and look up "function pointer declarations".

Janis

PS: And keep your posting line lengths around 72..78 characters per
line. (Look up "Usenet" and "Netiquette" if it is unclear why.)

Kenny McCormack

nepřečteno,
31. 8. 2021 6:41:2931.08.21
komu:
In article <5438567e-10f9-4a54...@googlegroups.com>,
hongy...@gmail.com <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. So I want to dig/find some clues from the extensive/exhaustive *nix
>man page. I'm not sure if there is a convenient way to do this.

Hi!

I don't understand brain surgery. I've made a few stabs at it, but all my
patients (so far) have died.

Can you help me?

--
To be evangelical is to spend every waking moment hovering around
two emotional states: fear and rage. Evangelicals are seriously the
angriest and most vicious bunch of self-pitying, constantly-moaning
whinybutts I've ever encountered.

Josef Moellers

nepřečteno,
31. 8. 2021 9:57:5431.08.21
komu:
On 31.08.21 12:33, 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. So I want to dig/find some clues from the extensive/exhaustive *nix man page. I'm not sure if there is a convenient way to do this.

I'm not sure if the manual pages will be of any help here, but analyzing
this is quite simple:

1) As there is a type designator ("int") at the beginning and a list of
(what looks like) parameters at the end, this looks like a function
declaration. So this is a function expecting three arguments of the
proper kind and returning an int.

2) Where there is usually a function *name*, there is a "*const
parse_packet" (put between parentheses to satisfy C's precendece rules),
so (leaving the "const" aside for a moment), "* parse_packet" is the
function "name", so "parse_packet" is the name of a pointer to the function.

3) The "const" in front of the pointer name means that this field is
"constant", so, once initialialized, cannot be changed any more.


Maybe check http://unixwiz.net/techtips/reading-cdecl.html

Josef

I can vaguely recall having seen a program which takes an arbitrarily
complex variable declaration and spits out a (human readable)
description of the declaration, eg
int *a; -> "a pointer to an int"
But I can't find it atm.

Keith Thompson

nepřečteno,
31. 8. 2021 11:16:3831.08.21
komu:
Yes, it's called "cdecl", also available online at https://cdecl.org/

$ cdecl
Type `help' or `?' for help
cdecl> explain int(*const parse_packet)(const char *, size_t, char **);
declare parse_packet as const pointer to function (pointer to const char, size_t, pointer to pointer to char) returning int
cdecl>

--
Keith Thompson (The_Other_Keith) Keith.S.T...@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Kaz Kylheku

nepřečteno,
31. 8. 2021 13:48:2331.08.21
komu:
On 2021-08-31, Kenny McCormack <gaz...@shell.xmission.com> wrote:
> In article <5438567e-10f9-4a54...@googlegroups.com>,
> hongy...@gmail.com <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. So I want to dig/find some clues from the extensive/exhaustive *nix
>>man page. I'm not sure if there is a convenient way to do this.
>
> Hi!
>
> I don't understand brain surgery. I've made a few stabs at it, but all my
> patients (so far) have died.

Please post the smallest (or smallest-brained) patient before they died,
the dead version of the patient, and a description of their actual
expected behavior.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Janis Papanagnou

nepřečteno,
31. 8. 2021 15:05:1731.08.21
komu:
On 31.08.2021 19:48, Kaz Kylheku wrote:
> On 2021-08-31, Kenny McCormack <gaz...@shell.xmission.com> wrote:
>> In article <5438567e-10f9-4a54...@googlegroups.com>,
>> hongy...@gmail.com <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. So I want to dig/find some clues from the extensive/exhaustive *nix
>>> man page. I'm not sure if there is a convenient way to do this.
>>
>> Hi!
>>
>> I don't understand brain surgery. I've made a few stabs at it, but all my
>> patients (so far) have died.
>
> Please post the smallest (or smallest-brained) patient before they died,
> the dead version of the patient, and a description of their actual
> expected behavior.

Please make sure to use a standardized scalpel and for reference
also a standard patient so that we can better compare the death
causes in our examination.

Eli the Bearded

nepřečteno,
31. 8. 2021 16:28:0731.08.21
komu:
In comp.unix.shell, Kaz Kylheku <563-36...@kylheku.com> wrote:
> On 2021-08-31, Kenny McCormack <gaz...@shell.xmission.com> wrote:
>> I don't understand brain surgery. I've made a few stabs at it, but all my
>> patients (so far) have died.
> Please post the smallest (or smallest-brained) patient before they died,
> the dead version of the patient, and a description of their actual
> expected behavior.

I don't think my Usenet privder will let me upload RFC-1437 attachments.

Elijah
------
panix is strict about "binaries"

Janis Papanagnou

nepřečteno,
1. 9. 2021 4:21:0601.09.21
komu:
Aha! Someone who is familiar with the most important RFCs.[*]

Janis :-)

[*] http://random.gridbug.de/rfcs0401.html

Josef Moellers

nepřečteno,
1. 9. 2021 4:49:2201.09.21
komu:
On 31.08.21 17:16, Keith Thompson wrote:
> Josef Moellers <josef.m...@invalid.invalid> writes:

>> I can vaguely recall having seen a program which takes an arbitrarily
>> complex variable declaration and spits out a (human readable)
>> description of the declaration, eg
>> int *a; -> "a pointer to an int"
>> But I can't find it atm.
>
> Yes, it's called "cdecl", also available online at https://cdecl.org/
>
> $ cdecl
> Type `help' or `?' for help
> cdecl> explain int(*const parse_packet)(const char *, size_t, char **);
> declare parse_packet as const pointer to function (pointer to const char, size_t, pointer to pointer to char) returning int
> cdecl>

Thanks for refreshing my memory!

Josef
0 nových zpráv