473,729 Members | 2,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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_p tr (a.k.a. std::tr1::share d_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 & acknowledgement s.

--
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
14 2831
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
[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
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.c pp

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<>.s ize() 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
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. "Introducti on 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 incomprehensibl e) 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
* 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 "constructo r".

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
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_p tr (a.k.a. std::tr1::share d_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 & acknowledgement s.

--
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_p tr method, but I didn't see it mention the real reason
why you might need a clone method over a boost::shared_p tr 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
* 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
* 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

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

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

Similar topics

46
2255
by: TTroy | last post by:
Hi, I'm just wondering why people/books/experts say "the function returns a pointer to.." or "we have to send scanf a pointer to.." instead of "the function returns the address of.." or "we have to send scanf the address of.." Isn't the lvalue called a POINTER TO and the (r)value called the ADDRESS OF?
5
7314
by: Stuart | last post by:
Ok let me explain: I am writing a c# program that calls into an unmanaged C++ third-party DLL. I have to make a number of calls and for simplification the protype I am calling is: bool fn(int *pResult); This result is used by other subsequent functions that I have to call. Q: Is it possible to call this function from C# declaring
12
2026
by: Sean | last post by:
I know I can pass a reference to a String into a Form by overloading the Constructor. Public Sub New(ByRef strDX As String) MyBase.New() InitializeComponent() End Sub
34
4874
by: Bob | last post by:
Hi, The compiler gives Warning 96 Variable 'cmdSource' is used before it has been assigned a value. A null reference exception could result at runtime. Dim cmdSource as SQlClient.SQLDataReader Try Set up the database read and do it. Catch ex as system.exception exception stuff here Finally
2
2177
by: anon.asdf | last post by:
Hi! Q. 1) How does one write: sizeof(array of 5 "pointers to double") ??? I know that sizeof(pointer to an array of 5 doubles) can be written as: sizeof(double (*));
0
9426
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9280
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8144
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4525
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
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
2
2677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2162
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.