best way to pass data around



Hi there,

So I have created a small IM app in gtk that can now connect and send data to my java IM server I created. Yippie... However I do have a question. in order to solve the problem of getting the text that I typed and the sockfd to the send_text function I created a struct.

typedef struct Data_To_Be_Sent {
        GtkWidget *scrolled_window_data_to_be_sent;
        GtkTextBuffer *buffer;
        GtkWidget *view_data_to_be_sent;
        int sockfd;
} Data_To_Be_Sent;

This is than passed into the send_text function from main.

button = gtk_button_new_with_label ("send text");
g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK
    (send_text), &data_to_be_sent);

once in the send_text function I can get to all those variables for instance, text = gtk_text_buffer_get_text (data_to_be_sent->buffer, &start, &end, FALSE);

My question is, is there a better way to do this? Is using a typedef struct a good idea? my grasp of C isn't so great. not that I don't know syntax it's just how to use that syntax sometimes and writing GTK really stretches the limits... I want to learn the best practices of course. :) any comments are welcome.

Thanks
Ken




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]