Interpreting some code

Discussion in 'C Programming' started by Chris Saunders, Jul 23, 2003.

  1. I came across a construction in some code I was reading that I have
    never seen before and hope that someone could tell me how to
    interpret this:

    int (*literalScanners[XML_N_LITERAL_TYPES])(const ENCODING *,
    const char *,
    const char *,
    const char **);

    It looks like a function declaration to me but the "[XML_N_LITERAL_TYPES]"
    part throws me off.

    Regards
    Chris Saunders
     
    Chris Saunders, Jul 23, 2003
    #1
    1. Advertising

  2. Chris Saunders

    Ben Pfaff Guest

    "Chris Saunders" <> writes:

    > int (*literalScanners[XML_N_LITERAL_TYPES])(const ENCODING *,
    > const char *,
    > const char *,
    > const char **);


    Array of pointers to functions returning int.
    --
    "Large amounts of money tend to quench any scruples I might be having."
    -- Stephan Wilms
     
    Ben Pfaff, Jul 23, 2003
    #2
    1. Advertising

  3. Chris Saunders <> scribbled the following:
    > I came across a construction in some code I was reading that I have
    > never seen before and hope that someone could tell me how to
    > interpret this:


    > int (*literalScanners[XML_N_LITERAL_TYPES])(const ENCODING *,
    > const char *,
    > const char *,
    > const char **);


    > It looks like a function declaration to me but the "[XML_N_LITERAL_TYPES]"
    > part throws me off.


    It's declaring an array of pointers to function, not declaring a
    function. There are XML_N_LITERAL_TYPES pointers in that array, and
    they each point to a function returning int and accepting parameters
    (const ENCODING *, const char *, const char *, const char **).

    --
    /-- Joona Palaste () ---------------------------\
    | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
    | http://www.helsinki.fi/~palaste W++ B OP+ |
    \----------------------------------------- Finland rules! ------------/
    "I wish someone we knew would die so we could leave them flowers."
    - A 6-year-old girl, upon seeing flowers in a cemetery
     
    Joona I Palaste, Jul 23, 2003
    #3
  4. Chris Saunders

    Tobias Oed Guest

    Chris Saunders wrote:

    > I came across a construction in some code I was reading that I have
    > never seen before and hope that someone could tell me how to
    > interpret this:
    >
    > int (*literalScanners[XML_N_LITERAL_TYPES])(const ENCODING *,
    > const char *,
    > const char *,
    > const char **);
    >
    > It looks like a function declaration to me but the "[XML_N_LITERAL_TYPES]"
    > part throws me off.


    That's an array with XML_N_LITERAL_TYPES items of pointers to function
    taking (const ENC...) as arguments and returning an int.
    Tobias.

    --
    unix http://www.faqs.org/faqs/by-newsgroup/comp/comp.unix.programmer.html
    clc http://www.eskimo.com/~scs/C-faq/top.html
    fclc (french): http://www.isty-info.uvsq.fr/~rumeau/fclc/
     
    Tobias Oed, Jul 23, 2003
    #4
  5. My thanks to all who responded.

    Regards
    Chris Saunders


    "Ben Pfaff" <> wrote in message
    news:...
    > "Chris Saunders" <> writes:
    >
    > > int (*literalScanners[XML_N_LITERAL_TYPES])(const ENCODING *,
    > > const char *,
    > > const char *,
    > > const char **);

    >
    > Array of pointers to functions returning int.
    > --
    > "Large amounts of money tend to quench any scruples I might be having."
    > -- Stephan Wilms
     
    Chris Saunders, Jul 23, 2003
    #5
  6. Chris Saunders

    Dan Pop Guest

    In <KBBTa.6718$> "Chris Saunders" <> writes:

    >I came across a construction in some code I was reading that I have
    >never seen before and hope that someone could tell me how to
    >interpret this:
    >
    >int (*literalScanners[XML_N_LITERAL_TYPES])(const ENCODING *,
    > const char *,
    > const char *,
    > const char **);
    >
    >It looks like a function declaration to me but the "[XML_N_LITERAL_TYPES]"
    >part throws me off.


    Then remove it and you're left with:

    int (*literalScanners)(const ENCODING *, const char * ...);

    which can be easily recognised as the declaration of a pointer to
    function. So, what do we have when we put "[XML_N_LITERAL_TYPES]" back
    in? An array of pointers to functions.

    Note that such declarations need not be that cryptical. A single typedef
    can do wonders:

    typedef int func_t(const ENCODING *, const char *, const char * ...);
    func_t *literalScanners[XML_N_LITERAL_TYPES];

    Now, it's glaringly obvious that literalScanners is an array of pointers.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
     
    Dan Pop, Jul 24, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rob Meade

    Interpreting the error message?

    Rob Meade, Jan 27, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    406
    Rob Meade
    Jan 28, 2004
  2. yzzzzz

    Interpreting JSP code

    yzzzzz, Apr 19, 2005, in forum: Java
    Replies:
    4
    Views:
    556
    Tom Arne Orthe
    Apr 21, 2005
  3. Alec S.
    Replies:
    5
    Views:
    688
    Alec S.
    Sep 11, 2004
  4. Chris Saunders

    Interpreting some C code

    Chris Saunders, Feb 6, 2004, in forum: C Programming
    Replies:
    3
    Views:
    581
    Vijay Kumar R Zanvar
    Feb 6, 2004
  5. zolli

    Interpreting mem_map init code

    zolli, Mar 27, 2005, in forum: C Programming
    Replies:
    4
    Views:
    453
    CBFalconer
    Mar 28, 2005
Loading...

Share This Page