The problem seems to be that you are assuming that parameters are both for input and ouput of a function. But in C, function parameters are always copies. So when you do:
void static notebook(GtkWidget *table, GtkWidget *notebook) {
notebook = gtk_notebook_new();
You are modifying the local copy of the notebook
pointer, not the one from main
. The notebook
pointer in main
remains uninitialized.
To do what you try, minimum changes, would be:
void static notebook(GtkWidget **table, GtkWidget **notebook) {
*notebook = gtk_notebook_new();
...
int main() {
GtkWidget *table;
GtkWidget *notebook;
...
notebook(&table, ¬ebook);
But doing that with every pointer is ugly and cumbersome. So I would recommend some refactoring:
- Functions that create a thing should return that thing.
- Functions that take a lot of related values should take a single value of type
struct whatever
. - Remember that struct parameters in C are usually passed as pointers, so you get the in-out parameter for free!
Something like this:
struct Notebook
{
GtkWidget *table;
GtkWidget *notebook;
};
void static notebook(struct Notebook *notebook) {
notebook->notebook = gtk_notebook_new();
...
}
int main(int argc, char *argv[]) {
Notebook nb;
...
notebook(&nb);
...
}