B
BGB / cr88192
It's not that hard to hide these things behind a few functions and
preprocessor macros -- BTDT.
The effective scheme comes down to just that -- you call your member
functions through pointers in the struct. How is this "murdering the
language"?
<--
A toy example will have just a few function pointers embedded in a
struct. You can achieve polymorhism of a sort.
When you move to a full-blown system, you realise that this simple
system doesn't provide you with the flexibility that you need. You
need to pass in a void pointer. You then need to query it for the
interface. You then need to get the function pointer from the
interface. You then need to adjust the pointer to the right base. Then
you call the function. It returns a void pointer which you have to
query for another interface ... The code doesn't look like C.
-->
one can wrap the whole mess in an API vaguely resembling the object system
exposed by JNI...
dycClass iface;
dycObject obj;
dycMethod mth;
float f;
....
iface=dycGetClass("myapp/mypkg/IFoo");
mth=dycIdxMethod(iface, "fooMethod(ii)f");
....
f=dycCallf(obj, mth, 3, 4);
however, all this proved somewhat awkward, and adds a lot of interface
overhead (via direct access via structs, casting, and function pointers).
so this is a problem...
a later extension allows things like:
void *fcn;
fcn=dycGetObjMethodAddr(obj, mth);
f=((float(*)(dycObject, int, int))fcn)(obj, 3, 4);
which can be used to reduce the overhead some, but doesn't much help
usability...
so, I am left partly considering a system which can be canonically mapped to
C structs, hence allowing a nicer C-level interface, but I am unsure if this
is a good route either (since as a cost, it could create physical dependency
on the class layout, essentially freezing runtime class layout, whereas the
current system allows extending classes with new fields or methods without
breaking any existing instances via a "versioning" system).
or such...