Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8359171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:03:42+00:00 2026-06-09T11:03:42+00:00

I have a small program where a gtk signal callback function needs 2 or

  • 0

I have a small program where a gtk signal callback function needs 2 or 3 variables.

I don’t want to make these global variables (The entire goal of the project is to be neat and tidy) and I don’t want to make a whole struct just so I can send a widget and a compiled regex to a function.

As far as I’ve seen g_signal_connect only allows for a single data variable.

Would the most efficient way of doing this perhaps be an array of void pointers to the two objects in question? Something like this?

void * data[2];
data[0] = widget;
data[1] = compiledregex;
g_signal_connect(save,"clicked",G_CALLBACK(callbackfunction),data);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:03:44+00:00Added an answer on June 9, 2026 at 11:03 am

    Of course you can use arrays of void pointers, but if you want to pass around values with different types (especially values whose type is longer than sizeof(void *)), you can’t use arrays. For these, you’ll almost certainly want to wrap them in a struct and pass the struct’s address as the data parameter.

    Example:

    struct my_struct *data = malloc(sizeof(*data));
    data->field_one = value_one;
    data->field_two = value_two; /* etc. */
    
    g_signal_connect(save, "clicked", callback, data);
    

    Of course, don’t forget to free(data) in the callback function (assuming it’s for single use).

    Edit: as you wanted an example with void **, here you are (this is ugly, and I don’t recommend you to use this — either because allocating a one-element array for primitive types is wasting your shoot or because casting a non-pointer to void * is bad practice…):

    void **data = malloc(sizeof(data[0]) * n_elements);
    
    type1 *element1_ptr = malloc(sizeof(first_item));
    *element1_ptr = first_item;
    data[0] = element1_ptr;
    
    /* etc. */
    

    To free them:

    int i;
    for (i = 0; i < n_elements; i++)
        free(data[i]);
    
    free(data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small program I want to execute to test something #include <map>
I am currently have a small program in Common Lisp, which I want to
I have this small program and it needs to create a small .txt file
I have made a small program in C# that I want to run in
I have written a small program which uses function pointers to do some numerical
I have a small program that batch handles files. These files use a map
I have a small program <350ish lines of code on 5 forms>. It works
i have a small program where an element is draged and dropped, when the
I have a small program to do in Java. I have a 2D array
I have a small program that's supposed to sample some value from a device

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.