Hi guys
A while a ago I asked about using C++ on a 8bit system, so the answer I got is no. But I really can see the benefit of using object like code, so I look around and fount out I can do something like that in C.
So what do you guys think if I write code something like these:
A while a ago I asked about using C++ on a 8bit system, so the answer I got is no. But I really can see the benefit of using object like code, so I look around and fount out I can do something like that in C.
So what do you guys think if I write code something like these:
Code:
typedef uint8_t (*func_ptr1_t)(void);
typedef uint8_t (*func_ptr2_t)(uint8_t);
typedef uint8_t (*func_ptr3_t)(uint8_t, uint8_t);
typedef struct{
uint8_t *buff;
...
uint8_t var1;
uint8_t var2;
uint16_t var3
uint16_t var4;
...;
func_ptr1_t method1;
func_ptr2_t method2;
func_ptr3_t method3;
...;
}obj_t;
void obj_init(obt_t object, uint8_t *buff, func_ptr1_t method1, ...){
object.buff = buff;
objcet.var1 = default1;
object.var2 = default2;
...;
object.method1 = method1;
object.method2 = method2;
...;
}
// main code
valitale uint8_t buffer[some_size];
valitale obj_t some_obj;
main(void){
obj_init(some_obj, buffer, func_1, func_2, ...)
while(1){
some_obj.method1();
...;
}
}