473,545 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1761
Richard Hayden wrote in news:cd20cdc.03 11230503.4ad104 58
@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_t o_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
7569
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 overloaded assignment operator implemented as follows: Point &Point::operator=( const Point *somePoint )
6
2203
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 problem is with the &. My second problem is with the const. Why should bind1st change the constness of the second argument of the function ?
7
1267
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 instances are created via a factory method that returns a Ref and all constructors are protected. My "problem" is the following. The Ref class is...
8
2028
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 constness of static members. Is there a way to do that? Also, is there a way for a static member function to guarantee constness of static members? TIA...
6
1863
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 class Base) of the createInstance function below that produces the output: Output:
2
1200
by: MaxMax | last post by:
I have a problem of constness. struct MyS { int x; } void MyFunc(MyS* pA) { }
14
2016
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 <boost/shared_ptr.hpp> #include <vector> #include <iterator> #include <iostream> class trial {
2
3563
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 { const typename cv; typename v; }*)&(value))->v) which requires value to be an lvalue, but avoid compiler warning (gcc) comparing to the brute...
13
1250
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 std::list is the same that it is in C arrays (const std::list makes const both the list and its content):
0
7473
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7661
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7815
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7763
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4949
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3458
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1891
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
712
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.