首页 > 解决方案 > 在终端中运行命令问题

问题描述

我有这个操作系统任务,代码不会在 MAC 终端中运行,我一直收到一个问题,上面写着“图像”。在这个问题上我能得到什么帮助吗?

这是代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>

// These two functions will run concurrently
void* print_i(void *ptr)
{
    printf("I am in i\n");
}
    void* print_j(void *ptr)
{
    printf("I am in j\n");
}
int main()
{
    pthread_t t1,t2;
    int rc1 = pthread_create(&t1, NULL, print_i, NULL);
    int rc2 = pthread_create(&t2, NULL, print_j, NULL);
    exit(0);
}

标签: c

解决方案


关键字 void(不是指针)在 C 中表示“无”。这是一致的。

正如您所指出的, void* 在支持原始指针(C 和 C++)的语言中表示“指向任何东西的指针”。这意味着您需要返回一些东西。

这就是您收到此类警告的原因。

如果你返回一些东西,比如返回 0;警告消失。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>

// These two functions will run concurrently
void* print_i(void *ptr)
{
    printf("I am in i\n");
    return 0;
}
    void* print_j(void *ptr)
{
    printf("I am in j\n");
    return 0;
}
int main()
{
    pthread_t t1,t2;
    int rc1 = pthread_create(&t1, NULL, print_i, NULL);
    int rc2 = pthread_create(&t2, NULL, print_j, NULL);
    exit(0);
}

您可以在此处了解更多信息:

https://linux.die.net/man/3/pthread_create


推荐阅读