Why wouldn't you give a name for your structs.
Code:
struct myCBConfig {
char* cmd; // Command to match
char* data; // Additional data to callback
void (*callback)(struct myCBConfig*, char* rawTcpData); // Callback to call
};
If you want to use typedef instead of struct name, you can write
Code:
typedef struct myCBConfig myCBConfig;
.
For more cleaner approach, I would write (YMMV)
Code:
struct myCBConfig;
typedef void CBFunction(struct myCBConfig*,char*);
struct myCBConfig {
char* cmd; // Command to match
char* data; // Additional data to callback
CBFunction *callback;
};
A sample usage of this code would be
Code:
void aCBfunction(struct myCBConfig*cf,char *foo) {
printf("Im useless..\n");
}
int main(void) {
struct myCBConfig f;
char c;
f.callback=aCBfunction;
f.callback(&f,&c);
return 0;
}
The same thing in C++ would be
Code:
#include <cstdio>
class myCallback {
public:
char* cmd; // Command to match
char* data; // Additional data to callback
virtual void operator()(char *rawTcpData)=0; //Callback to call
};
class aCallback : public myCallback {
void operator()(char *foo) { printf("Im useless..\n"); }
};
int main(void) {
aCallback cb;
myCallback &f=cb;
char c;
f(&c);
return 0;
}