Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "d" stand for in d-pointer?

Qt makes heavy use of the PIMPL idiom in their development process: https://wiki.qt.io/D-Pointer

As I've read here: "The name 'd-pointer' stems from Trolltech's Arnt Gulbrandsen, who first introduced the technique into Qt, making it one of the first C++ GUI libraries to maintain binary compatibility even between bigger release.". But nobody says what "D" stands for.

So what does the "D" stand for in D-Pointer?

like image 299
Jacob Krieg Avatar asked Oct 23 '19 10:10

Jacob Krieg


People also ask

How do you define a pointer in C++?

Pointers must be declared before they can be used, just like a normal variable. The syntax of declaring a pointer is to place a * in front of the name. A pointer is associated with a type (such as int and double ) too.

What is pointer in C++ and types?

A pointer is a variable that stores the memory address of an object. The pointer then simply “points” to the object. The type of the object must correspond with the type of the pointer. Pointers are used extensively in both C and C++ for three main purposes: To allocate new objects on the heap.

How do I find the value of a pointer?

Declare a pointer variable with the same type as the normal variable. Initialize the pointer variable with the address of normal variable. Access the value of the variable by using asterisk (*) - it is known as dereference operator.

How do you initialize a pointer in C++?

You need to initialize a pointer by assigning it a valid address. This is normally done via the address-of operator (&). The address-of operator (&) operates on a variable, and returns the address of the variable. For example, if number is an int variable, &number returns the address of the variable number.


2 Answers

From this page Data Sharing with Class (an old docs from QT), it says:

Before we can share an object's private data, we must separate its interface from the private data using an idiom called "d-pointer" (data pointer)

So, d-pointer means data-pointer

like image 159
Amadeus Avatar answered Oct 29 '22 00:10

Amadeus


I'll add my own answer, since I remember the day it happened.

I was trying to extend something while maintaining binary compatibility, and noticed that there was a pointer called 'data' that I could reuse for a different purpose. So I made a private class for implementation-related data (a pimpl), put both the old data and my new data there, and since the existing name seemed to fit I kept the name.

I abbreviated it from data to d after a short meeting later on the same day, where we agreed that the pattern I'd invented stumbled upon was good and we should use it widely, and that d-> was short enough and unique enough to be used everwhere as a mark of implementation-specific fields.

At the same meeting, we decided to put implementation-specific data in d-> as a matter of policy from then on, mostly in order to keep the number of includes down, but also to keep the declared API clean in general. Fewer private variables in the class declaration means few opportunities for error, fewer temptations, fewer things that can conflict with subclass naming and so on. Better hygiene.

like image 38
arnt Avatar answered Oct 28 '22 23:10

arnt