By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,236 Members | 1,843 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,236 IT Pros & Developers. It's quick & easy.

Finally, a release candidate of the "Pointers" document (introduction to pointers)

P: n/a
Not yet perfect, but:

http://home.no.net/dubjai/win32cpptu...ters/ch_01.pdf
http://home.no.net/dubjai/win32cpptu...1_examples.zip

To access the table of contents, use the "Bookmarks" tab in Adobe
Acrobat.

Comments, corrections, praise, nits, etc., are still welcome!

1 Pointers.
1.1 Introduction to the basics.
1.1.1 How to obtain a pointer to a given object, and how to use that pointer.
1.1.2 The nullpointer value, valid and invalid pointers.
1.1.3 How to implement out-arguments by using pointers.
1.1.4 How to implement in-arguments by using pointers.
1.1.5 How to use C++ style references instead of C style pointers for arguments.
1.1.6 How to access main arguments.
1.1.7 Const-correctness for pointers and references.
1.2 Run-time polymorphism.
1.2.1 Polymorphism.
1.2.2 The concepts of data representations and linked data structures.
1.2.3 C-style polymorphism with simulated dynamic types (just one actual type).
1.2.4 Basic use of dynamic memory allocation & deallocation.
1.2.5 How to use function pointers to simulate dynamic types, C-style.
1.2.6 Using real types and inheritance for logical sub-types, mostly C-style.
1.2.7 Using vtables, mostly C-style (also a few words about abstract classes, etc.).
1.2.8 C++ virtual member functions.
1.2.9 C++ destructors and polymorphic delete.
1.3 Safety for dynamically allocated objects.
1.3.1 Object ownership and the C++ std::auto_ptr.
1.3.2 Exception safety for new: RAII and C++ constructors.
1.3.3 Ensure dynamic allocation by using C++ access specifiers & friendship.
1.3.4 An aside on wrapping boost::shared_ptr (a.k.a. std::tr1::shared_ptr).
1.3.5 Ensure that smart pointers are used, by overloading operator new.
1.3.6 Combat slicing by removing access to copy assignment.
1.3.7 Value copying problems & possible solutions.
1.3.8 Cloning as a solution to ownership and aliasing problems.
1.3.9 Intentional sharing as a solution to ownership and aliasing problems.
1.4 An introduction to exceptions.
1.4.1 How to generate and handle exceptions.
1.4.2 Exception usage example: conversion between numeric values and text.
1.4.3 Exceptions and pointers, including the concept of "hard" exceptions.
1.5 Basic serialization and de-serialization.
1.5.1 A serialization format for hierarchical data structures.
1.5.2 De-serialization: a simple non-OO recursive descent parser.
1.5.3 Serialization: a simple generator using intrusive OO code.
1.5.4 A generator using non-intrusive non-OO code (introducing C++ RTTI).
1.5.5 A generator using non-intrusive OO code (introducing the visitor pattern).
1.6 Notes on C++ inheritance as it pertains to pointers.
1.6.1 Passing Base/Derived-class pointers by reference.
1.6.2 The Liskov substitution principle (more about mutable/immutable).
1.6.3 Covariance, contravariance and invariance.
1.7 Closing words & acknowledgements.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 8 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
Hi Alf P. Steinbach,

Your PDF looks very neat at first look. Just now I have downloaded your
PDF..

You could have given the summary about your work, the reason for the
work, what you expect from the readers etc..

Thanks

Gopal

Dec 8 '05 #2

P: n/a
[Followups set to acllcc++]

Alf P. Steinbach said:
Not yet perfect, but:

http://home.no.net/dubjai/win32cpptu...ters/ch_01.pdf


GhostView doesn't like it. It gave an error on every page I tried (ten or
so). Just blank pages.

Since I don't have (and don't want to have) Adobe Acrobat, I was unable to
review the document.

Not complaining - just letting you know.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Dec 8 '05 #3

P: n/a
Alf P. Steinbach wrote:
Not yet perfect, but:

http://home.no.net/dubjai/win32cpptu...ters/ch_01.pdf
http://home.no.net/dubjai/win32cpptu...1_examples.zip
To access the table of contents, use the "Bookmarks" tab in Adobe
Acrobat.

Comments, corrections, praise, nits, etc., are still welcome!

It has nothing to do with the pointer stuff, but this fragment from your
in_by_pointer.cpp

typedef std::vector<int> IntVector;
..
..
..
double sum = 0.0;
for( std::size_t i = 0; i < pNumbers->size(); ++i )
{
sum += pNumbers->at( i );
}

arises the question: What is the (most) correct type for the loop variable
in such a for-loop as above?

As std::vector<>.size() returns a std::vector<>::size_type, shouldn't this
be

double sum = 0.0;
for( IntVector::size_type i = 0; i < pNumbers->size(); ++i )
{
sum += pNumbers->at( i );
}

In my implementation std::vector<>::size_type is just a typedef for
std::size_t, but is this guaranteed?
Dec 8 '05 #4

P: n/a
On Thu, 08 Dec 2005 08:04:13 GMT, al***@start.no (Alf P. Steinbach)
wrote:
Not yet perfect, but:
http://home.no.net/dubjai/win32cpptu...ters/ch_01.pdf
http://home.no.net/dubjai/win32cpptu...1_examples.zip

To access the table of contents, use the "Bookmarks" tab in Adobe
Acrobat.

Comments, corrections, praise, nits, etc., are still welcome!


First impression: This is not a tutorial but a book.
Second impression: This is not a book about pointers but a book about
various C/C++ styles, idioms and techiques.
The book includes:
- basic concepts - e.g. "Introduction to the basics"
- advanced concepts - e.g. "Using vtables"
- How-tos - e.g. "How to access main arguments"
- techiques- e.g. "Basic serialization"
- idioms - e.g. "RAII"
- etc.

While each chapter contains valuable information (and is written by a
competent author) the current organization makes it difficult to read
the book for the presumed target audience, beginners and intermediate
programmers. From the reader's point of view it is not clear if a
chapter contains absolut necessary basic information or special (and
currently incomprehensible) cases that can be defered. The book is not
written as step-by-step introduction from basic to advanced.
An alternative would be to present the chapters as 'items' in the
style of Meyers and Sutter. Each item could be labeled as 'basic',
'intermediate' or 'advanced' to guide the reader.
Some remarks to the 'pointer' part of the book. Although it is
mentioned in the text I would emphasize from the beginning that:

1. Pointers are typed: A pointer can only point to an object of one
type. The type is static, i.e. it cannot be changed (of course, you
need to separately explain pointers to void). Strictly speaking, there
is no 'pointer' in C/C++ only a 'pointer to T'.

2. A pointer is a physical _and_ a logical reference to an object of
type T. As you explain, a pointer is a physical refernce because it
contains the address in memory of the pointed-to object. But it is
also a logical refernce. The user can reference the pointed-to object
without ever knowing its physical address. This 'double-nature' makes
pointers so 'expressive'.

Best regards,
Roland Pibinger
Dec 8 '05 #5

P: n/a
* Roland Pibinger:
[snip] The book is not
written as step-by-step introduction from basic to advanced.
It is.

There are some forward-references mentioned in passing, e.g. use of
the term "constructor".

But otherwise it's all one long brick by brick construction from
fundamentals up, definitions/explanations (and not the least important,
a problem showing the necessity) before use, always.

Some remarks to the 'pointer' part of the book. Although it is
mentioned in the text I would emphasize from the beginning that:

1. Pointers are typed: A pointer can only point to an object of one
type. The type is static, i.e. it cannot be changed (of course, you
need to separately explain pointers to void).


Pointers void are in section 1.3.5.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 8 '05 #6

P: n/a
Alf P. Steinbach wrote:
Not yet perfect, but:

http://home.no.net/dubjai/win32cpptu...ters/ch_01.pdf
http://home.no.net/dubjai/win32cpptu...1_examples.zip

To access the table of contents, use the "Bookmarks" tab in Adobe
Acrobat.

Comments, corrections, praise, nits, etc., are still welcome!

1 Pointers.
1.1 Introduction to the basics.
1.1.1 How to obtain a pointer to a given object, and how to use that pointer.
1.1.2 The nullpointer value, valid and invalid pointers.
1.1.3 How to implement out-arguments by using pointers.
1.1.4 How to implement in-arguments by using pointers.
1.1.5 How to use C++ style references instead of C style pointers for arguments.
1.1.6 How to access main arguments.
1.1.7 Const-correctness for pointers and references.
1.2 Run-time polymorphism.
1.2.1 Polymorphism.
1.2.2 The concepts of data representations and linked data structures.
1.2.3 C-style polymorphism with simulated dynamic types (just one actual type).
1.2.4 Basic use of dynamic memory allocation & deallocation.
1.2.5 How to use function pointers to simulate dynamic types, C-style.
1.2.6 Using real types and inheritance for logical sub-types, mostly C-style.
1.2.7 Using vtables, mostly C-style (also a few words about abstract classes, etc.).
1.2.8 C++ virtual member functions.
1.2.9 C++ destructors and polymorphic delete.
1.3 Safety for dynamically allocated objects.
1.3.1 Object ownership and the C++ std::auto_ptr.
1.3.2 Exception safety for new: RAII and C++ constructors.
1.3.3 Ensure dynamic allocation by using C++ access specifiers & friendship.
1.3.4 An aside on wrapping boost::shared_ptr (a.k.a. std::tr1::shared_ptr).
1.3.5 Ensure that smart pointers are used, by overloading operator new.
1.3.6 Combat slicing by removing access to copy assignment.
1.3.7 Value copying problems & possible solutions.
1.3.8 Cloning as a solution to ownership and aliasing problems.
1.3.9 Intentional sharing as a solution to ownership and aliasing problems.
1.4 An introduction to exceptions.
1.4.1 How to generate and handle exceptions.
1.4.2 Exception usage example: conversion between numeric values and text.
1.4.3 Exceptions and pointers, including the concept of "hard" exceptions.
1.5 Basic serialization and de-serialization.
1.5.1 A serialization format for hierarchical data structures.
1.5.2 De-serialization: a simple non-OO recursive descent parser.
1.5.3 Serialization: a simple generator using intrusive OO code.
1.5.4 A generator using non-intrusive non-OO code (introducing C++ RTTI).
1.5.5 A generator using non-intrusive OO code (introducing the visitor pattern).
1.6 Notes on C++ inheritance as it pertains to pointers.
1.6.1 Passing Base/Derived-class pointers by reference.
1.6.2 The Liskov substitution principle (more about mutable/immutable).
1.6.3 Covariance, contravariance and invariance.
1.7 Closing words & acknowledgements.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


Section 1.3.8 and 1.3.9 talk about a clone solution that requires a
virtual clone function, and then states this as a problem with using a
clone solution.
However, you can use a clone solution that does not require the base
class to ahve a virtual clone function (or derived class having clone
function).
See following clone smart pointers:
http:://code.axter.com/copy_ptr.h
http:://code.axter.com/cow_ptr.h
http:://code.axter.com/clone_ptr.h

All above clone smart pointers do not require clone functions for the
target T type.

This section makes the comparison between using clone method and using
boost::shared_ptr method, but I didn't see it mention the real reason
why you might need a clone method over a boost::shared_ptr method, and
the pros of using a clone smart pointer over using a shared_ptr.
See following link for more info:
http://www.codeguru.com/Cpp/Cpp/algo...le.php/c10407/

Dec 8 '05 #7

P: n/a
* Roland Pibinger:

Each item could be labeled as 'basic',
'intermediate' or 'advanced' to guide the reader.


For someone (a novice) who hasn't yet been indoctrinated in what
should be regarded as basic, intermediate or advanced, what matters,
as I see it, is the need for various things in practical programming,
and how difficult those things are to grasp given the foundations
already laid down.

Anyway, since the organization of this document is a brick-by-brick
build-up of knowledge and techniques it follows that its sections
not just are in order from basic to advanced, but provide a clear
cut definition (as opposed to feelings) of what's more advanced ;-).

I think a pre-conceived, emotionally and socially based categorization,
rather than one based on what must logically come first, is giving us a
host of students fresh out of college or university with gaping holes in
their education.

Cheers,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 8 '05 #8

P: n/a
* Axter:

Section 1.3.8 and 1.3.9 talk about a clone solution that requires a
virtual clone function, and then states this as a problem with using a
clone solution.


Thanks. Could you provide a quote? I'd like to fix that because that
was not my intention.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 8 '05 #9

P: n/a

Alf P. Steinbach wrote:
* Axter:

Section 1.3.8 and 1.3.9 talk about a clone solution that requires a
virtual clone function, and then states this as a problem with using a
clone solution.
Thanks. Could you provide a quote? I'd like to fix that because that
was not my intention.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

The following is listed under 1.3.9
Problems with our clone-it! solution to the copying side-effect and
aliasing problems include
More complicated implementation code than necessary.
More awkward client code than necessary (dereferencing, calls to
clone).
Algorithmic (not just operational) inefficiency.

Since the above is under section 1.3.9 (Intentional sharing as a
solution to ownership and aliasing problems), I'm assuming the above is
being used to justify using shareing method versus cloning method.

If you're making the comparison, I think you should also include COW
pointers which work like a clone pointer and a shared smart pointer put
together.
From what I've read so far, the document looks pretty good, and I think

it will be a good reference document. (Good Job)

Dec 8 '05 #10

P: n/a
On Thu, 08 Dec 2005 12:40:00 GMT, al***@start.no (Alf P. Steinbach)
wrote:
For someone (a novice) who hasn't yet been indoctrinated in what
should be regarded as basic, intermediate or advanced, what matters,
as I see it, is the need for various things in practical programming,
and how difficult those things are to grasp given the foundations
already laid down.

Anyway, since the organization of this document is a brick-by-brick
build-up of knowledge and techniques it follows that its sections
not just are in order from basic to advanced, but provide a clear
cut definition (as opposed to feelings) of what's more advanced ;-).


It would be interesting to hear the opinion of _real_ novices about
the comprehensibility of the text.

Best regards,
Roland Pibinger
Dec 8 '05 #11

P: n/a
Val
Looking good.
Two ideas:

- An index or chapter overview.
- Include "formal" definitions as well.

Dec 8 '05 #12

P: n/a
* Val:
Looking good.
Two ideas:

- An index or chapter overview.
The "Bookmarks" tab in Acrobat provide a table of contents.

Click on any section title and go to that section.

- Include "formal" definitions as well.


Uh, that's the standard... ;-)

Cheers,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 9 '05 #13

P: n/a
* Roland Pibinger:
On Thu, 08 Dec 2005 12:40:00 GMT, al***@start.no (Alf P. Steinbach)
wrote:
For someone (a novice) who hasn't yet been indoctrinated in what
should be regarded as basic, intermediate or advanced, what matters,
as I see it, is the need for various things in practical programming,
and how difficult those things are to grasp given the foundations
already laid down.

Anyway, since the organization of this document is a brick-by-brick
build-up of knowledge and techniques it follows that its sections
not just are in order from basic to advanced, but provide a clear
cut definition (as opposed to feelings) of what's more advanced ;-).


It would be interesting to hear the opinion of _real_ novices about
the comprehensibility of the text.


<url:
http://groups.google.no/group/alt.comp.lang.learn.c-c++/browse_frm/thread/f3a096decfa9b96b/231115cb00c83eba?tvc=1#231115cb00c83eba>

includes comments from novices, experienced and experts. It seems the main
stumbling block for a complete novice was section 1.2.3. That's been reworked,
but since nobody have commented on the new version I don't know how that is now.

I'm unable to say how real they, or for that matter you, are. ;-)

Cheers,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 9 '05 #14

P: n/a
Alf P. Steinbach wrote
Not yet perfect, but:

http://home.no.net/dubjai/win32cpptu...ters/ch_01.pdf
http://home.no.net/dubjai/win32cpptu...1_examples.zip

To access the table of contents, use the "Bookmarks" tab in Adobe
Acrobat.

Comments, corrections, praise, nits, etc., are still welcome!


First, I'd like to thank you for your great job and very intelligible
paper.
I'd not consider myself as a newbie but I'm reading it with interest.

If you don't mind I will share my comments from time to time while will
be moving on with it.

For now I found only a small typo in chapter 1.1.4:

"And the compiler enforces this restriction, so that average is
probited*** from changing anything in the IntVector that pNumbers
points to."

*** it should be prohibited, I think so.

By the way, is this document going to be a part of some bigger paper, a
book?

Cheers
--
Mateusz Loskot
http://mateusz.loskot.net

Dec 12 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.