Now, imagine you want one of the library function to return a pointer to one of its function ... what will you do ?
In C, you must have a struct FarPtr and have to call it. Not flexible. You need a special case whether the pointer is near or far, etc.
In C++, you can have
Code: Select all
virtual class Callback {
virtual operator();
}
Note that i'm no C++ guru, but what i try to have is a framework where callback() can be called (you don't even see you have something else than a function pointer ... otherwise callback.call() would have been required ... not here baby

)
Now, you can extend that class with NearCallBack, which just perform a near call, or
Code: Select all
class FarCallback :public Callback {
inline operator() {
unsigned ret;
asm("lcall %1":"=a"(ret):"0"(code),"m"(&CallGate));
}
private:
unsigned code; //!< identifies the command to be called
FarPtr CallGate; //!< what will you jump to ;-)
}
The same technique can be used to build up Callbacks from the user world to the library (but the calling mechanism will be more complex as we need to go one DPL level
down, which hasn't been foreseen by Intel developers).