Constness with pointers to pointers etc.

Discussion in 'C++' started by Richard Hayden, Nov 23, 2003.

  1. Hi,

    I understand such pointers as 'const int* const ip' and 'const int*
    ip' etc., but I'm getting confused when seeing things like 'const int*
    const* ip' (i.e. with two or more asterisks). Clearly pointers to
    pointers like this will require an expansion of the syntax to
    accommodate for all of the possible extra combinations (i.e. must
    specify the constness of the pointer ip and the constness of the
    pointer, to which ip is pointing). Is there a reference (or someone
    here) which/who can tell me how the syntax for such complicated
    pointer declarations works?

    Thanks,

    Richard Hayden.
    Richard Hayden, Nov 23, 2003
    #1
    1. Advertising

  2. Richard Hayden wrote in news:cd20cdc.0311230503.4ad10458
    @posting.google.com:

    > Hi,
    >
    > I understand such pointers as 'const int* const ip' and 'const int*
    > ip' etc., but I'm getting confused when seeing things like 'const int*
    > const* ip' (i.e. with two or more asterisks). Clearly pointers to
    > pointers like this will require an expansion of the syntax to
    > accommodate for all of the possible extra combinations (i.e. must
    > specify the constness of the pointer ip and the constness of the
    > pointer, to which ip is pointing). Is there a reference (or someone
    > here) which/who can tell me how the syntax for such complicated
    > pointer declarations works?
    >


    const int a;

    is another way of writing

    int const a;

    Its the one and only exception to the rule that a qualifier (const or
    volatile) goes after that which it qualifies.

    int const * const * const * const cp_to_cp_to_cp_to_int;
    int const * * const * const cp_to_cp_to_p_to_int;

    From your statement above, the declaration that "confuses" you:

    const int* const* ip;

    rewrite it "correctly" (;-)/YMMV)

    int const * const *ip;

    then read it backwards "ip is a pointer to a const pointer to a
    const int".

    HTH

    Rob.
    --
    http://www.victim-prime.dsl.pipex.com/
    Rob Williscroft, Nov 23, 2003
    #2
    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. Martin Magnusson

    Casting away constness

    Martin Magnusson, Nov 17, 2003, in forum: C++
    Replies:
    1
    Views:
    383
    tom_usenet
    Nov 17, 2003
  2. Trevor Lango

    Casting Away Constness

    Trevor Lango, Jan 2, 2004, in forum: C++
    Replies:
    15
    Views:
    2,395
    Ron Natalie
    Jan 2, 2004
  3. Replies:
    14
    Views:
    824
    Ian Collins
    Apr 4, 2006
  4. Javier
    Replies:
    9
    Views:
    344
    James Kanze
    May 18, 2008
  5. Kevin Walzer

    Re: PIL (etc etc etc) on OS X

    Kevin Walzer, Aug 1, 2008, in forum: Python
    Replies:
    4
    Views:
    383
    Fredrik Lundh
    Aug 13, 2008
Loading...

Share This Page