Chris M. Thomasson
2017-07-25 07:25:04 UTC
Fwiw, here is a crude "pre-alpha" attempt at getting vtables, and
allowing for only a single pointer's worth of overhead wrt using its
functionality. The code can be found here:
https://pastebin.com/raw/QPssvGJR
(pastebin raw, without ads... :)
And gives the following output for me:
______________________
(000000000060FE30:ct_person_create):(name:Chris M. Thomasson)
(000000000060FE30:ct_employee_print):(id:103)
(000000000060FE30:ct_person_print):(name:Chris M. Thomasson)
(000000000060FE30:ct_employee_destroy):(id:103)
(000000000060FE30:ct_person_destroy):(name:Chris M. Thomasson)
_______________________________________
(000000000060FE30:ct_person_create):(name:Jane Doe)
(000000000060FE30:ct_employee_print):(id:1203)
(000000000060FE30:ct_person_print):(name:Jane Doe)
(000000000060FE30:ct_employee_destroy):(id:1203)
(000000000060FE30:ct_person_destroy):(name:Jane Doe)
______________________
Afaict, this might have the possibility to be "somewhat" useful?
Ummm.. Well, take a look at lines 17-24:
______________________
#define ct_object_vtable(mp_self) \
((((struct ct_object_vtable*)(*((void**)(mp_self)))))
#define ct_object_print(mp_self, mp_file) \
(ct_object_vtable(mp_self)->fp_print((mp_self), (mp_file))))
#define ct_object_destroy(mp_self) \
(ct_object_vtable(mp_self)->fp_destroy((mp_self))))
______________________
Ummm.... Is that kosher? Damn...
The code for main is:
_____________________
int main(void)
{
struct ct_employee employee;
if (!ct_employee_create(&employee, "Chris M. Thomasson", 103))
{
struct ct_person* const person = &employee.m_person;
ct_object_print(&employee, stdout);
ct_object_destroy(person);
}
printf("\n_______________________________________\n");
if (!ct_employee_create(&employee, "Jane Doe", 1203))
{
struct ct_person* const person = &employee.m_person;
ct_object_print(person, stdout);
ct_object_destroy(person);
}
return 0;
}
_____________________
Afaict, the overall result has a little OOP spice about it? Humm...
Will have more time tomorrow to drill down on its details; sorry about
that. ;^o
allowing for only a single pointer's worth of overhead wrt using its
functionality. The code can be found here:
https://pastebin.com/raw/QPssvGJR
(pastebin raw, without ads... :)
And gives the following output for me:
______________________
(000000000060FE30:ct_person_create):(name:Chris M. Thomasson)
(000000000060FE30:ct_employee_print):(id:103)
(000000000060FE30:ct_person_print):(name:Chris M. Thomasson)
(000000000060FE30:ct_employee_destroy):(id:103)
(000000000060FE30:ct_person_destroy):(name:Chris M. Thomasson)
_______________________________________
(000000000060FE30:ct_person_create):(name:Jane Doe)
(000000000060FE30:ct_employee_print):(id:1203)
(000000000060FE30:ct_person_print):(name:Jane Doe)
(000000000060FE30:ct_employee_destroy):(id:1203)
(000000000060FE30:ct_person_destroy):(name:Jane Doe)
______________________
Afaict, this might have the possibility to be "somewhat" useful?
Ummm.. Well, take a look at lines 17-24:
______________________
#define ct_object_vtable(mp_self) \
((((struct ct_object_vtable*)(*((void**)(mp_self)))))
#define ct_object_print(mp_self, mp_file) \
(ct_object_vtable(mp_self)->fp_print((mp_self), (mp_file))))
#define ct_object_destroy(mp_self) \
(ct_object_vtable(mp_self)->fp_destroy((mp_self))))
______________________
Ummm.... Is that kosher? Damn...
The code for main is:
_____________________
int main(void)
{
struct ct_employee employee;
if (!ct_employee_create(&employee, "Chris M. Thomasson", 103))
{
struct ct_person* const person = &employee.m_person;
ct_object_print(&employee, stdout);
ct_object_destroy(person);
}
printf("\n_______________________________________\n");
if (!ct_employee_create(&employee, "Jane Doe", 1203))
{
struct ct_person* const person = &employee.m_person;
ct_object_print(person, stdout);
ct_object_destroy(person);
}
return 0;
}
_____________________
Afaict, the overall result has a little OOP spice about it? Humm...
Will have more time tomorrow to drill down on its details; sorry about
that. ;^o