[英]Pthreads cast void * argument into int array
我正在處理用C ++編寫的以下代碼:
int *V;
V = new int[nfilas*ncols];
iret=pthread_create(&threadList[i], NULL, worker_function, (void*)(&V)[nfilas*ncols]);
將“ V”(一個int數組)傳遞給此函數:
int *matrix=(int*)ptr;
for( int r=0; r<nfilas; ++r ){
for( int c=0; c<ncols; c++ ){
printf("%d ", matrix[r*ncols+c]);
}
我的問題是我無法將void指針轉換為int元素數組。 我該如何解決? 我已經嘗試了很多事情,但是我不知道自己在做什么錯。 先感謝您
您的演員陣容有很多事情要做...
用pthread_create(..., V); // V is already a pointer
您的線程pthread_create(..., V); // V is already a pointer
pthread_create(..., V); // V is already a pointer
您可以安全地從int *
為void *
並返回...
int *V;
V = new int[nfilas*ncols];
iret = pthread_create(
&threadList[i], NULL, worker_function, static_cast<void *>(V));
在您的工作中...
int *matrix = static_cast<int *>(ptr);
for(int r = 0; r < nfilas; r++){
for(int c = 0; c < ncols; c++){
printf("%d ", matrix[r*ncols+c]);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.