It is necessary to make a practical one in the S. language. I don’t understand the language at all and somehow it’s badly absorbed by me. Therefore, please help and, if possible, explain.
#include <pthread.h> #include <stdio.h> /* Находим простое число с порядковым номером N, где N — это значение, на которое указывает параметр ARG. */ void* compute_prime(void* arg) { int candidate = 2; int n = *((int*)arg); while (1) { int factor; int is_prime = 1; /* Проверка простого числа путем последовательного деления. */ for (factor = 2; factor < candidate; ++factor) if (candidate % factor == 0) { is_prime = 0; break; } /* Это то простое число, которое нам нужно? */ if (is_prime) { if (--n == 0) /* Возвращаем найденное число в программу. */ return (void*)candidate; } ++candidate; } return NULL; } int main() { pthread_t thread; int which_prime = 5000; int prime; /* Запускаем поток, вычисляющий 5000-е простое число. */ pthread_create(&thread, NULL, &compute_prime, &which_prime); /* Выполняем другие действия. */ /* Дожидаемся завершения потока и принимаем возвращаемое им значение. */ pthread_join(thread, (void*)&prime); /* Отображаем вычисленный результат. */ printf("The %dth prime number is %dn", which_prime, prime); return 0; } Knocks error in line 21:
cast-pointer from integer of different size [-Wint-to-pointer-cast] return (void *) candidate;
Tell me how to solve the problem and explain what exactly is the matter?
int candidate = 2;onlong candidate = 2;. But the problems of the code are much wider. - αλεχολυτ