| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Richard Hayden" |
| Date: |
23 Nov 2003 07:03:05 AM |
| Object: |
Constness with pointers to pointers etc. |
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.
.
|
|
| User: "Rob Williscroft" |
|
| Title: Re: Constness with pointers to pointers etc. |
23 Nov 2003 07:20:32 AM |
|
|
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/
.
|
|
|
|

|
Related Articles |
Win32, writing API's etc.. Tutor and Software Engineer(Java, C++, PC computer, Internet, etc) using map, list etc. in const methods Preprocessor, nested files etc. constrained_value type for ranged integers etc. Noob to C++, trying to get syntax, etc. How to use #ifndef #define, etc, in a macro definition optimizing code: sort algorithm, random numbers etc. Best resources for optimization?
| EVIL Matrox Graphics Inc , STEALS MGA Settings/VIRTUAL DESKTOP from Windows 98, 2000 etc Why we need symbol files for GDI32.dll or Kernel32.dll etc... How to loop in a vector (set, map, etc) from iterator i to iteratorj Unix advanced sockets etc. Refs. in std::vector, ctor arguments, etc MS Access And Excell data access through c++(API ,Connector,etc) debugging... dereferencing, & etc.
|
|
|