所以,我正在做这个简单的代码示例:
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#define NUM_TRABALHADORAS 3
pthread_t tid[NUM_TRABALHADORAS];
void* printsomething(void *arg){
printf("Entrei\n");
}
int main (void) {
for(int i = 0; i < NUM_TRABALHADORAS; i++){
pthread_create(&(tid[i]), NULL, &printsomething, NULL);
}
}
我编译:
gcc -Wall -pthread inicio.c
并收到此警告:
inicio.c: In function ‘printsomething’:
inicio.c:12:2: warning: control reaches end of non-void function [-Wreturn-type]
}
你能帮帮我吗?
答案 0 :(得分:1)
函数printsomething
应该返回一个void
指针,但它什么也没有返回。让函数返回NULL
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#define NUM_TRABALHADORAS 3
pthread_t tid[NUM_TRABALHADORAS];
void * printsomething(void * args){
printf("Entrei\n");
return NULL;
}
int main (void) {
for(int i = 0; i < NUM_TRABALHADORAS; i++){
pthread_create(&(tid[i]), NULL, &printsomething, NULL);
}
}