> Hi Vitaliy, > I apologise for not posting anything yet about this subject, but I am > trying to process all the information about it. > The problem I have at the moment is that I just discovered that the CSS > C compiler does not deal very well with function pointers especially in > structs, hence is delaying my research into the subject. > The first issue I had to overcome was the fact that I am not only > writing a program using OOP I am also writing the infrastructure to > generate the objects and actually that is the most important part. I > will also start by not having inheritance but I can see how that could > be done. The other issue I had is the "VTable" I could not understand > its function. A "VTable" is a tool used to support virtual functions. Rather than put all the function pointers directly into your object struct, you put them into a separate struct and point each object of the class at the separate, VTable, struct. For example: // Forward declare the actual class object typedef struct MyClass; // Now declare the structure containing pointers to the virtual methods typedef struct MyClass_VTable { void (*Initialize) (struct MyClass *this, int a, int b); int (*DoSomething)(struct MyClass *this, int a); } MyClass_VTable; // Now declare the actual object typedef struct MyClass { MyClass_VTable *pVtable; int a_field; int another_field; } MyClass; // Now declare the methods for the class void MyClass_Initialize(struct MyClass *this, int a, int b); int MyClass_DoSomething(struct MyClass *int a); // Create an instance of the VTable struct and initialize // it to point to the functions for the class MyClass_VTable MyClass_vtable = { MyClass_Initialize, MyClass_DoSomething }; // Now to create an instance of the MyClass object MyClass myObject = { &MyClass_vtable, 0, 0 }; // To call a virtual function void someFunction(void) { ... myObject.pVtable->Initialize(&myObject, 3, 5); } > So this is how I am doing it: > > I have a function called checksumCalculator() which takes two parameter, > an int bufferSize and an array of chars buffer which is the packet. It > returns a char checksumCal which represents the checksum. > > To transform it into a class I created three, setSize, setBuffer, > calculatechecksum. I also have three fields, bufferSize, buffer and > checksumCal. > > So far all seems ok, but then what I envisage is a struct with the three > fields and three function pointers one for each of the methods. When an > instance of the class is created the three fields are initialised and > the function address passed to the pointers. Is this what you do? > I found that when I try this I can not manipulate the fields of the > struct with the class methods, how did you get around that? > > I am probably making a mess out of this, so apologies in advance. > > Best Regards > Luis You don't need a VTABLE or function pointers in a struct if you do not use "virtual" functions. In this case your object is just the struct with three fields in it. -- Bob Ammerman RAm Systems -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist