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

    From Janis Papanagnou@21:1/5 to hongy...@gmail.com on Tue Aug 31 12:41:14 2021
    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.)


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

    Regards,
    HY


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to All on Tue Aug 31 03:33:50 2021
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to hongy...@gmail.com on Tue Aug 31 10:41:24 2021
    In article <5438567e-10f9-4a54-93e3-7b8699acdd00n@googlegroups.com>, hongy...@gmail.com <hongyi.zhao@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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Josef Moellers@21:1/5 to hongy...@gmail.com on Tue Aug 31 15:57:48 2021
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Keith Thompson@21:1/5 to Josef Moellers on Tue Aug 31 08:16:33 2021
    Josef Moellers <josef.moellers@invalid.invalid> writes:
    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.

    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.Thompson+u@gmail.com
    Working, but not speaking, for Philips
    void Void(void) { Void(); } /* The recursive call of the void */

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Kenny McCormack on Tue Aug 31 17:48:18 2021
    On 2021-08-31, Kenny McCormack <gazelle@shell.xmission.com> wrote:
    In article <5438567e-10f9-4a54-93e3-7b8699acdd00n@googlegroups.com>, hongy...@gmail.com <hongyi.zhao@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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Kaz Kylheku on Tue Aug 31 21:05:12 2021
    On 31.08.2021 19:48, Kaz Kylheku wrote:
    On 2021-08-31, Kenny McCormack <gazelle@shell.xmission.com> wrote:
    In article <5438567e-10f9-4a54-93e3-7b8699acdd00n@googlegroups.com>,
    hongy...@gmail.com <hongyi.zhao@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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Eli the Bearded@21:1/5 to 563-365-8930@kylheku.com on Tue Aug 31 20:28:02 2021
    In comp.unix.shell, Kaz Kylheku <563-365-8930@kylheku.com> wrote:
    On 2021-08-31, Kenny McCormack <gazelle@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"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Josef Moellers@21:1/5 to Keith Thompson on Wed Sep 1 10:49:17 2021
    On 31.08.21 17:16, Keith Thompson wrote:
    Josef Moellers <josef.moellers@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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Eli the Bearded on Wed Sep 1 10:21:01 2021
    On 31.08.2021 22:28, Eli the Bearded wrote:
    In comp.unix.shell, Kaz Kylheku <563-365-8930@kylheku.com> wrote:
    On 2021-08-31, Kenny McCormack <gazelle@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.

    Aha! Someone who is familiar with the most important RFCs.[*]

    Janis :-)

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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)