Question: ```
typedef struct
{
    char struct_variable_1a[10];
    char struct_variable_1b[12];
} struct1;

typedef struct
{
    char struct_variable_1a[10];
    char struct_variable_1b[12];
    int struct_variable_2c;
} struct2;

typedef struct1 *struct1_ptr;
typedef struct2 *struct2_ptr;

static void sampleFunction(struct1_ptr valueToInsert){
//this code does some stuff here
}

int main(){

struct1_ptr struct1_var = (struct1_ptr) malloc(sizeof(struct1));
strcpy(struct1_var->struct_variable_1a, "some value");
strcpy(struct1_var->struct_variable_1b, "some value");

sampleFunction(struct1_var);

return 0;
}

```

I have a sample code in `C programming` as shown above. In the `main` method, I am trying to pass a variable of type `struct1_ptr` for `sampleFunction` method call.
This works like a charm. But when I want to pass a variable of type `struct2_ptr`, the compiler is throwing error. Basically, I am java developer. I want to reuse this `sampleFunction` method for any variable type in its parameter in general. Kindly help me in this.

Answer: 
change your function from:

```
static void sampleFunction(struct1_ptr valueToInsert){
//this code does some stuff here
}

```

to:

```
static void sampleFunction(void* valueToInsert){
//this code does some stuff here
}

```

If you want to identify the type of the structure add a second parameter to your function that contains the size of the struct.

//Edit:   

Inside the function you have to cast your variable back to the structure you want to use. for example:

```
strcpy(((struct1_ptr)valueToInsert)->struct_variable_1a, "some value");

```
You could emulate inheritance in C like this:

```
typedef struct
{
    char struct_variable_1a[10];
    char struct_variable_1b[12];
} struct1;

typedef struct
{
    struct1 parent; /* Must be first element! */
    int struct_variable_2c;
} struct2;

```

And then call like this:

```
sampleFunction((struct1_ptr)ptr_to_struct2);

```

or (I would favor this, because there's no cast):

```
sampleFunction(&ptr_to_struct2->parent);

```

Just note that you won't be able to access members of struct2 in function without casting it back.

These work for simple structures, but if you do anything more complex, using C++ would be more approriate.