if have a routine like this which I want the main application to access...
char* get_widget_name(widget_t* w) {
return name(w);
}
both the following macro's I want to "hide" while obviously using within get_widget_name
#define GET_WIDGET(self) (&(self)->base.widget)
#define name(self) (GET_WIDGET(self)->name)
I'm basically using unions in structures to "emulate" c++ inheritance in C.
You publish the information to be used in the main application in a header file. In this example, it might be:
#ifndef WIDGET_H_INCLUDED
#define WIDGET_H_INCLUDED
typedef struct widget widget_t;
extern char *get_widget_name(widget_t *w);
#endif /* WIDGET_H_INCLUDED */
And then in the implementation file (widget.c
), you define the structure contents and the macros and use them as you see fit, without making them available to the main application at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With