I am stuck in a simple pointer/casting problem:
I am try to pass as a argument to the pthread function in pthread_create an array of 2 structs. Here is the code:
struct sockaddr_in addr_left, addr_right;
struct sockaddr_in* addr_vec [2] = {&addr_left, &addr_right};
pthread_create (&thread_forward, NULL, thread_func_forward, (struct sockaddr**)addr_vec);
Inside thread_func_forward:
void * thread_func_forward (void * argv) {
struct sockaddr_in* addr_left = ((struct sockaddr_in*)argv + 0);
struct sockaddr_in* addr_right = ((struct sockaddr_in*)argv + 1);
}
For some reason it does not work properly, the program can execute the last lines without segmentation fault but when I access to the members of the structs, they are completely changed