c - 在终端中运行命令问题
问题描述
我有这个操作系统任务,代码不会在 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);
}
解决方案
关键字 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);
}
您可以在此处了解更多信息:
推荐阅读
- css - 标题栏完全冲到顶部的框
- php - 如何使用 pdo php mysql 更新多个表
- linux - 端口转发命令
- python - 气流 - 如果不存在,则使用 xcom 原子创建
- html - onclick 事件无法点击图标
- salesforce - 从配置文件中删除记录类型
- xml - 直接从 Jenkins 工作区读取测试结果文件
- python - 获取 TypeError:__init__() 在 Django 项目中有一个意外的关键字参数“upload_to”?
- azure - 通过 Dockerized env 登录 Azure 时找不到 Azure 订阅
- excel - 如何在 Perl 中将路径从 VBA 传递到 $ARGV [0]