# Thread: How make function with ability to vary member of interest in structure?

1. ## How make function with ability to vary member of interest in structure?

Hello all,

I've read 180567 and 178521 on the forum and I feel no wiser regarding my idea of a function implementation.

I have a link list of data that contains a pointer to another data type. Within that data type there are numerous members. I need help understanding how far I can use "redirection"

I want to create a function that calculates the delta array & therefore I can later run that output on a histogram function.

See following pseudo code on method of creating delta array.

Code:
`Delta1 = (A->next -> B -> C.member_of_interest) - (A -> B -> C.member_of_interest);`
Alternatively one could say

Code:
`Delta1 = (A2 -> B -> C.member_of_interest) - (A -> B -> C.member_of_interest);`
Therefore my idea of function is
Code:
`d_type *delta_array my_function(**A_linklist, ?member_of_interest?)`
So i can get
Code:
`Delta2 = (A2 -> B -> C.member_of_interest2) - (A -> B -> C.member_of_interest2);`
by running
Code:
`d_type *x_array my_function(**A_linklist, ?member_of_interest2?);`
I intend to use the triple ref method so I can find delta array as I transition to link list null pointer.

Regards,
Wes

N.B notice the bold 2.

2. How many 'member_of_interest' are there?

Anytime you start putting numeric suffixes on symbols is a sign you should be thinking about an array.
Then your 'member_of_interestx' parameter simply becomes an index into that array.

3. Hey Salem,

Imagine
Code:
```typedef struct a_struct {
struct a_struct *next;
b_t *b;
} a_t;

typedef struct {
c_t *c;
int blah
} c_t;

typedef struct {
int t_start;
int t_center;
int t_end;
} c_t;```
Therefore
Delta1 = ((A->next) -> B -> C.t_start) - (A -> B -> C.t_start);

Basically I want to have a function whereby
delta_t_start = generic_function(**A, ?pointer/offset to c.t_start?)
delta_t_end =
generic_function(**A, ?pointer/offset to c.t_end?)

4. Are all elements of c_t the same type?

If they are, you can probably cook something up with offsetof - cppreference.com