0

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

6
  • 1
    The latter is the preferred way; that is the purpose of the user_data parameter to signal functions, after all. Commented Dec 3, 2015 at 1:10
  • why though, I never got the reason behind that Commented Dec 3, 2015 at 9:51
  • What do you mean, why you need user_data parameters? Or are you confused about something else? And are you familiar with any other GUI toolkits besides GTK+ or programming languages other than C? (This last question may help me make explaining the situation easier.) Commented Dec 3, 2015 at 15:38
  • I meant why is declaring them globally something bad, I'm familiar with Java and cpp, and I'm familiar with no other gui toolkits Commented Dec 3, 2015 at 20:07
  • 2
    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. Commented Dec 3, 2015 at 20:26

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.