How can I convert it to
struct pollfd **pollFDConverted;
You don't want to do that, the compiler needs to know the number of elements of the last dimension, on the other hand a thread handler uses a pointer to void
as parameter and you can pass whatever you want to it (except a pointer to function).
Just convert to the proper type (in this case I'm reading a 2D array of int
s via a pointer to an array of n int
s, you can adapt this to your struct
):
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
enum {rows = 2, cols = 3};
static void *thread_handler(void *arg)
{
int (*arr)[cols] = arg;
for (int row = 0; row < rows; row++)
{
for (int col = 0; col < cols; col++)
{
printf("%d ", arr[row][col]);
}
printf("\n");
}
return NULL;
}
int main(void)
{
int arr[rows][cols] = {{1, 2, 3}, {4, 5, 6}};
pthread_t thread;
if (pthread_create(&thread, NULL, thread_handler, arr) != 0)
{
perror("pthread_create");
exit(EXIT_FAILURE);
}
if (pthread_join(thread, NULL) != 0)
{
perror("pthread_join");
exit(EXIT_FAILURE);
}
return 0;
}