Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Constness with pointers to pointers etc.

Reply
Thread Tools

Constness with pointers to pointers etc.

 
 
Richard Hayden
Guest
Posts: n/a
 
      11-23-2003
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.
 
Reply With Quote
 
 
 
 
Rob Williscroft
Guest
Posts: n/a
 
      11-23-2003
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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Constness with standard containters of pointers Javier C++ 9 05-18-2008 09:27 AM
Constness of the container of shared_ptr and the constness of it elements PengYu.UT@gmail.com C++ 14 04-04-2006 01:57 AM
reference to reference and constness problems with bind1st Marc C++ 6 07-06-2004 02:01 PM
Casting Away Constness Trevor Lango C++ 15 01-02-2004 10:27 PM
Casting away constness Martin Magnusson C++ 1 11-17-2003 01:30 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57