26 ms·
C++ pointers-to-members have no standard structure and are implementation defined. But in no implementations they have pointers to instances inside them. If tha
by boguscoder 3y ago
C++ pointers-to-members have no standard structure and are implementation defined. But in no implementations they have pointers to instances inside them. If that was the case Why would you need an instance (again) pointer/reference to use pointer-to-member?
In most implementations they just encode an offset
- WalterBright 3y agoThe pointer to instance part is the `this` pointer. > C++ pointers-to-members have no standard structure and are implementation defined. A missed opportunity, though every C++ compiler I've examined did it the same way.
- boguscoder 3y agoBut again, ‘this’ pointer is not in any way stored inside pointer-to-member. Caller has to provide one
- deleted 3y ago[deleted]
- amluto 3y ago> The pointer to instance part is the `this` pointer. What do you mean? The this pointer isn’t computed until you try to call the pointer-to-member-function.
- AdieuToLogic 3y ago>> The pointer to instance part is the `this` pointer. > What do you mean? The this pointer isn’t computed until you try to call the pointer-to-member-function. Think of it from a compiler writer's perspective. The implicit parameter when using a pointer-to-member function is the function pointer itself. The `this` (instance) pointer must be passed explicitly when invoking it (along with whatever other parameters the function requires). Ergo: >> The pointer to instance part is the `this` pointer.
- lallysingh 3y agoPointer to what, exactly? It doesn't make sense for it to be an object instance pointer, because you can use the same pointer to member on several different objects instances. If one instance's pointer was embedded in the pointer-to-member, it wouldn't work for other instances. I have no idea what the format of a pointer-to-member is. It sure looks like a small closure.
- WalterBright 3y agoSee https://news.ycombinator.com/item?id=39812834 https://news.ycombinator.com/item?id=39812834 for a more complete explanation.
- amluto 3y agoIf I follow that link and end up here: https://www.digitalmars.com/articles/b68.html https://www.digitalmars.com/articles/b68.html I find: > C++ and D diverge here. D has the notion of a delegate, aka “fat pointer”, which is a pair consisting of a pointer to the member function and a pointer to the ‘this’ object. The virtualness of the member function was resolved at the point where the address of the member function was taken … > Alternatively, C++ has the notion of a member function pointer, which is independent of whatever object is used to call it. Such an object is provided when the member function is called Which sounds right. But you said: > The C++ pointer-to-member is a fairly confusing concept. What it actually is is a pair - a pointer to the instance of the struct, and a pointer to a function in that struct. Which is neither consistent with that text nor with how C++ works. The D concept of a pointer to member is the fat pointer that encodes this. C++’s is the horrible lambda-ish thing that can find the method starting with any compatible this pointer. Yuck.
- WalterBright 3y ago> But you said Yeah, I miswrote it. Hence the link to my article about it.