473,394 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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.
Jul 22 '05 #1
1 1750
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/
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Trevor Lango | last post by:
I want to be able to cast away the constness of a private member variable in a member function of a class. I have the private data member declared as follows: const double x; I have an...
6
by: Marc | last post by:
T x; T foo(T, T); bind1st(ptr_fun(foo), x) creates a function object that takes an argument of type T const&. This does not work if T is already a reference type like int const&. So my first...
7
by: Gonçalo Rodrigues | last post by:
Hi all, I have a class, call it Object of heap-allocated objects. They are managed via a smart pointer class Ref (actually a template class but that does not matter for the problem). Object...
8
by: Srini | last post by:
Hello all, I was just wondering about this. A const member function guarantees constness of the object within the function body. But there's no way for a member function to guarantee the...
6
by: Querejeto | last post by:
Hello: Is it possible to detect programmatically the constness of a member function when it is called? That is, I would like to see a generic implementation (i.e. it does not depend on the...
2
by: MaxMax | last post by:
I have a problem of constness. struct MyS { int x; } void MyFunc(MyS* pA) { }
14
by: PengYu.UT | last post by:
In the following program, I want an iterator contain pointer pointing to constant object not const pointer. If it is possible would you please let me know how to do it? #include...
2
by: Laurent Deniau | last post by:
I am looking for the "cleanest" way to cast away the constness of a pointee in C89, something like const_cast<T*>() in C++. Actually, I am using: #define CONST_CAST(typename,value) \ (((union {...
13
by: Javier | last post by:
Hello, I have some cuestions about constness with standard containers and pointers. Supose I have a list of pointers to some class B: std::list< B * list; I have readed that constness in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.