C - 警告:控制到达非空函数的结束

时间:2016-10-20 21:40:05

标签: c compiler-errors

所以,我正在做这个简单的代码示例:

#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]
}
你能帮帮我吗?

1 个答案:

答案 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);
    }
}