473,385 Members | 1,311 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,385 software developers and data experts.

Pointers In C++

A pointer is a variable which stores the address of another
variable. There are two important operators when working with pointers
in C++: the address of (&) operator and the value of (*) operator.
They have been overloaded in C++ so they may have different uses in
different contexts.

How much storage space does a pointer consume?
Use sizeof(ptr) without the '*' operator to determine the memory
utilised on your system. Irrespective of datatype or whether the
pointer points to a single variable or array, as a general rule,
pointers must use the same amount of memory space.

The & operator gives us the address of a variable and * gives us the
value of a variable at a specified address.

Please tell me something more about Pointer in C++.
www.onlinevideogallery.com
Jun 27 '08 #1
4 1525
On Jun 26, 9:23 am, "Alf P. Steinbach" <al...@start.nowrote:
* Stefan Ram:
Alisha <alisha0...@gmail.comwrites:
A pointer is a variable which stores the address of another
variable.
IIRC, both »pointer« and »variable« are not defined explicitly
by ISO/IEC 14882:2003(E).
[...]
The definition of "variable" in §3/4 is succinct and complete,
and I don't understand how you can refer to it above, "3p4",
and still maintain that there's no definition of the term.
Ditto, the term "pointer" is defined by §3.9.2/1 with
reference §8.3.1.
Independantly of the clarity (I have no problem with it, but
clarity is subjective), the terms are in italics in the cited
text. And (§1.3) "Terms that are used only in a small portion
of this International Standard are defined where they are used
and italicized where they are defined." Of course, I'm not
sure that either variable or pointer would qualify as "used only
in a small portion" of the standard. But the intent is clear:
the cited text is a definition, in the sense of the standard.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #2
Alf P. Steinbach wrote:
* Stefan Ram:
>"Alf P. Steinbach" <al***@start.nowrites:
>>>»An object is a region of storage that has a type.«
Not in C++.

»An object is a region of storage. [...] An object has a type«

ISO/IEC 14882:2003(E), 1.8

Sorry, a region of storage does not have a type.
The proposed definition of "object" does not entail the claim that any
region of storage has a type. It says that an object is a region of storage
that has a type. If a region of storage does not have a type, it would not
qualify as an object according to the proposed definition.

The standard, on the other hand, is very clear that some regions of storage
have types (namely those regions of storage that happen to be objects).

A region of storage may be part of many objects, with different types.
Yes, and nothing in the proposed definition of "object" would contradict
that.

Best

Kai-Uwe Bux
Jun 28 '08 #3
Alf P. Steinbach wrote:
* Kai-Uwe Bux:
>Alf P. Steinbach wrote:
>>* Stefan Ram:
"Alf P. Steinbach" <al***@start.nowrites:
>»An object is a region of storage that has a type.«
Not in C++.
»An object is a region of storage. [...] An object has a type«

ISO/IEC 14882:2003(E), 1.8
Sorry, a region of storage does not have a type.

The proposed definition of "object" does not entail the claim that any
region of storage has a type. It says that an object is a region of
storage that has a type.

You're contradicting yourself.

>If a region of storage does not have a type, it would not
qualify as an object according to the proposed definition.

I think that's true.

So it's not compatible with C++.
That sentence only talks about those regions of storage that are not object.
But if x is an object and objects are regions of storage, then some region
of storage _is_ the object x. In that case, that region of storage has a
type since the object x has a type.

>The standard, on the other hand, is very clear that some regions of
storage have types (namely those regions of storage that happen to be
objects).

Chapter & verse please.
You have already been given the necessary quotes:

[1.8/1]: An object is a region of storage. ["object" in italics]

Note that this is a conceptual stipulation that identifies objects with
regions of storage. Consequently, all attributes of an object become
attributes of the region of storage that this object happens to be (there
is no conceptual distinction between the object and the region of storage
that it _is_).

Therefore, when the standard goes [in the same clause] to say that objects
have storage duration, lifetime, and type it _follows_ that certain regions
of storage (namely those that happen to be objects) have storage duration,
lifetime, and type.

Should be corrected if anything so bad has managed to sneak into the
standard! :-)
Maybe. The standard could say "An object occupies a region of storage" or
"An object has a region of storage". But the standard chose to use "is" and
thereby chose to identify objects and their regions of storage on a
conceptual level. Whether that decision is _wise_ is a different matter.

BTW: This is very much like the differences of materialist and
non-materialist accounts of what a human is. Materialist would say a human
_is_ a body and non-materialists would say a human _has_ a body. The former
would then go on to say that if humans had immortal souls, it would follow
that certain bodies had immortal souls. (This is one of the reasons that
materialists tend to be critical of religion and that religious
philosophers tend to be critical of materialism. Both agree that the
inference is valid:-)

>>A region of storage may be part of many objects, with different types.

Yes, and nothing in the proposed definition of "object" would contradict
that.

It does.
How so? Let's say you have an object x of type T which has a member x.a of
type S. Also, suppose that x_ptr is a char* so that

[x_ptr, x_ptr+sizeof(T) )

_is_ the object X and a_ptr is a char* so that

[a_ptr, a_ptr + sizeof(S) )

_is_ the object x.a. Then the region [a_ptr, a_ptr+sizeof(S) ) has type S
and the region [x_ptr, x_ptr + sizeof(T) ) has the type T. Of course, that
even goes when the two regions of storage coincide. BTW: in that case, x
and x.a _are_ the same(!) object according to the standard (which makes
more sense that one might think at first: after all any change to x will
affect a).
Although there exists a silly convoluted interpretation (reading
"has" as "is associated with" and "a" as "at least one") where it doesn't.
There is nothing silly about it. It just follows straight from the
identification made by the standard.
However, it doesn't matter, for it goes only to the practical reason why
regions of storage are not regarded as having types.

Understanding the difference between storage (untyped) and object (typed)
is
fundamental. For example, a void* doesn't point to storage of type void.
But it's no big deal to take that untyped storage and make an object out
of it via e.g. placement new.

I think it's wrong of you to try to sow confusion about this distinction.
You may not like the conceptual identification of objects with regions of
storage, but the italics in the standard [1.8/1] make it very clear that
the statement "An object is a region of storage" is meant as a definition
of the term object. Since it is supposed to be a definition, it makes an
identification on the conceptual level (for better or worse).

Maybe, what one would want is something like "an object is a typed region of
storage". So, two objects would be the same if and only if they occupy the
same region in memory _and_ have the same type. Creation of an object could
then be regarded as the act of typing a certain region of memory.
BTW: I don't think the identification is actually all that harmful. The
standard is not a book to teach C++ but just a specification that should
allow one to deduce the observable behavior of C++ programs. I do not (yet)
see how that [1.8/1] or my interpretation of it negatively impacts on that.

Best

Kai-Uwe Bux
Jun 28 '08 #4
Kai-Uwe Bux wrote:
Maybe. The standard could say "An object occupies a region of storage" or
"An object has a region of storage". But the standard chose to use "is" and
thereby chose to identify objects and their regions of storage on a
conceptual level. Whether that decision is _wise_ is a different matter.
Well, the question would be: does the object still exist if it had been
written to tape when the computer has been melted and turned into cola
cans? The above wording avoids such (purely philosophical, of course)
questions, because they're meaningless in the discussion of a running
C++ program.
Jul 10 '08 #5

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

Similar topics

27
by: Susan Baker | last post by:
Hi, I'm just reading about smart pointers.. I have some existing C code that I would like to provide wrapper classes for. Specifically, I would like to provide wrappers for two stucts defined...
3
by: ozbear | last post by:
This is probably an obvious question. I know that pointer comparisons are only defined if the two pointers point somewhere "into" the storage allocated to the same object, or if they are NULL,...
9
by: Mikhail Teterin | last post by:
Hello! I'd like to have a variable of a pointer-to-function type. The two possible values are of type (*)(FILE *) and (*)(void *). For example: getter = straight ? fgetc : gzgetc; nextchar...
12
by: Lance | last post by:
VB.NET (v2003) does not support pointers, right? Assuming that this is true, are there any plans to support pointers in the future? Forgive my ignorance, but if C# supports pointers and C# and...
14
by: Alf P. Steinbach | last post by:
Not yet perfect, but: http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01.pdf http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01_examples.zip To access the table of...
92
by: Jim Langston | last post by:
Someone made the statement in a newsgroup that most C++ programmers use smart pointers. His actual phrase was "most of us" but I really don't think that most C++ programmers use smart pointers,...
4
by: Josefo | last post by:
Hello, is someone so kind to tell me why I am getting the following errors ? vector_static_function.c:20: error: expected constructor, destructor, or type conversion before '.' token...
25
by: J Caesar | last post by:
In C you can compare two pointers, p<q, as long as they come from the same array or the same malloc()ated block. Otherwise you can't. What I'd like to do is write a function int comparable(void...
54
by: Boris | last post by:
I had a 3 hours meeting today with some fellow programmers that are partly not convinced about using smart pointers in C++. Their main concern is a possible performance impact. I've been explaining...
2
by: StevenChiasson | last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller. This is more or less, your...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.