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");

```
unfortunately C does not support method overloading / polymorphism. So you have to write your own methodology.

one is, to give the type as a first parameter to every overloaded function. Inside the function you walk along with a simple switch-case to jump to the original function implementation (like struct1\_sampleFunction() and struct2\_sampleFunction()).

another is, to put an RECORDCORE struct at the beginning of every struct and fill the type into this RECORDCORE, so each function can dispatch according to this data.

in both cases you have to change the prototype from "struct1\_ptr value" to "void \*value"