Reputation: 638
I have a function that is connected to the "changed" signal for a combobox in gtk, which in turn calls another function read_button_config.
The read_button_config takes the main window, a combobox and a vcontainer which I had not declared globally as parameters
Which way is better for passing these parameters: - declaring the parameters globally - passing the parameters as a struct to the first function, and passing the struct members to the read_button_config function?
Please let me know why you think either is better, I want to know what is a better way for future development
Upvotes: 0
Views: 63
Reputation: 19375
Which way is better for passing these parameters: - declaring the parameters globally - passing the parameters as a struct to the first function, and passing the struct members to the read_button_config function?
The latter is the preferred way; that is the purpose of the user_data
parameter to signal functions, after all.
Declaring them globally isn't bad. Rather, using the user_data
is idiomatic. It's a bit harder since you have to manage the memory for the user_data
yourself, but using user_data
keeps your code modules more self-contained. You will need to decide what you want to do.
– andlabs
Upvotes: 1