« first day (3155 days earlier)      last day (2018 days later) » 

09:11
How can I create a pointer to an instance function? is there any way at all?
nwp
nwp
Wrong room. Ask here.
 
6 hours later…
15:08
Finally stayed in a wood cabin, had a baby bird living under the same roof.
 
1 hour later…
user7659542
16:13
What is usually the best way to connect abstraction layers?
I have a service on one side and a driver on the other. One approach would be to do smth like "#include <myDriver.h>" in my service and call the driver's function in the service
another approach would be to have a layer between those two, meaning you don t include the driver in the service
and it is the generic intermediate layer which includes the driver
user7659542
myService.c
#include <myDriver.h>
void serviceDoSmth()
{
    //some calculations
	int result = 33;

    driveBar(33);
}

myDriver.c

void driveBar(int res)
{
    //drive something here
}
user7659542
or rather
user7659542
myService.h
typedef struct
{
    int (*intermediateLayerDoSmth)(int res);
} foo_t;

myService.c
#include <intermediateLayer.h>

void initService(foo_t* ctxt)
{
    ctxt->intermediateLayerDoSmth = doSmth;
}

void serviceDoSmth(foo_t* ctxt)
{
    //some calculations
	int result = 33;

    ctxt->intermediateLayerDoSmth(result)
}

intermediateLayer.c
 
1 hour later…
17:43
Back to Canada already.
18:22
@traducerad I assume you're not talking about a kernel mode driver. Also didn't you ask this a few days ago? I'd avoid unnecessary abstractions, and especially using multiple process. The solution will become obvious when you write the interface for the driver, and the associated tests. Remember keep it simple. Also for compatibility, and deployment reasons I'd prefer a C style API facing the user.
18:50
Yesterday I wrote this kind of thing to exposure one of my codes as a kind of SDK. No intermediate layer necessary.
19:15
Missed the flight again ... that's $200+ re-ticketing fee. How to design the worst highway system so travellers can be late & have to pay re-ticketing fee.
19:57
So I was reading a colleague's code and he a child class override a parent class function with a different (covariant) return type.

1st, I didn't think that was allowed. But apparently it's a thing. Then I was wondering how that works if the return type conversion requires an offset due to multiple inheritance.
Tried it out in Godbolt... OMG...
@StackedCrooked If you're monitoring coliru's inputs, it's this: coliru.stacked-crooked.com/a/ec8a97f5410f92a5
I don't monitor them.
I just store them.
And occasionally browse through random stuff.
ITT, your IP is logged, your stuff stored.
@Mysticial It's a neat feature. However, when I tried to use it I quickly ran into restrictions that make it mostly unusable. For example if you change the return type from X* to std::vector<X*> then the covariance doesn't work anymore.
@StackedCrooked Yeah, deep covariance isn't really a thing.
It used to be a thing in the 60s. But that's long time ago :)
20:04
Long story short, if the overriding return type requires an offset to convert to the parent type, the function is duplicated and it generates an extra vtable entry.
@Mysticial Oh. Hadn't considered stuff like that.
So what you write in the child class becomes a separate function that only exists in the child class and it's sub-classes. But the compiler automatically generates a version of the function that returns the parent's version as well to put into the vtable slot for where the parent expects it to be.
Damn, all that for a feature that nobody uses.
I assume this gets even messier with longer inheritance chains and even more covariants.
As now you have a gazillion extra vtable entries.
@Mysticial and this is why I require override on virtual items
20:11
@Mgetz How does override affect anything here?
@StackedCrooked Actually, that can't work because what if X* needs an offset?
@Mysticial Good question.
Seems like multiple inheritance does introduce a can of worms.
And they managed to hide it pretty well.
Recently we ran into this problem with a unique_ptr<> with a custom deleter.
Someone wants to assign a child class pointer into a parent class pointer. But the deleter prevented it from compiling.
But once we added an overload to the deleter to allow the assignment, we realized that this will fall apart on offset conversions.
Hence my question about dynamic_cast<void*> yesterday.
20:31
@Mysticial And with shared_pointer, if the type is incomplete it will compile but be UB (which can be really hard to trace back, MSVC for example, omits the delete operation, meaning that every ts where delete "could be called" need to have the correct header included - with no warning from the compiler)
@Mysticial I understand how the code works but I have no clue why anybody would do this... I mean, you can just static_cast, etc to get the right type?
@StackedCrooked In this case, I think the standard could be broadened a bit. (not a feature request though) Instead of just subclasses to parent classes, you can make it any convertible type. The compiler then inserts the conversion for you when it makes the duplicate function.
IOW, this could be made possible:
virtual std::string Parent::func();
virtual const char* Child::func() override;
Again, not a feature request.
@Mikhail Why would it compile but be UB?
^ deleting an incomplete type, for a motivation that I still don't understand that compiles.
@Mikhail You can delete an incomplete type?
20:46
why the fuck?
It does give warnings though.
MSVC doesn't emit those errors, possibly because it was written in the 1980s when this was some clever programing technique...
Anyways, its been about two years and I still have PTSD from that bug
Hmm... unique_ptr avoids it because it has sizeof() that requires a complete type.
C:/msvc/v19_14/include\memory(2053): error C2338: can't delete an incomplete type
Only inside unique_ptr. But it still lets you manually delete an incomplete type.
21:02
There's a SFINAE trick to check if a type is complete or not. Then you can do a static assert on this. I recall boost used to do this for their smart pointers.
21:50
@Mysticial override causes compilation to fail if someone changes anything in the signiture
@Mgetz But not the return type - which is what's changing here.
@Mikhail actually it does in my experience
@Mysticial return type should be checked if not I believe the compiler is non-compliant
notice no errors
@Mikhail unique pointer and operator delete are different
either way, end of day for me
Is it 4:20 in Colorado?
21:56
@Mgetz Then MSVC, ICC, GCC, and Clang are all non-compliant: godbolt.org/z/jQ1fGv
^ That code is criminally insane, there are about three better ways to accomplish the same thing.

« first day (3155 days earlier)      last day (2018 days later) »