编译Unix高级编程源代码出现的格式warning
来源:互联网 发布:泰格至尊软件说明书 编辑:程序博客网 时间:2024/05/22 09:49
今天在编译Unix高级编程源代码,在make后报警告: 格式 ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘pthread_self’ [-Wformat]
经过查找资料,pthread_self()是POSIX标准的实现,它的返回值是pthread_t,pthread_t在Linux中实际是无符号长整型,即unsigned long。我把‘%d’改为‘%ld’后警告解决。
#include "apue.h"#include <pthread.h>struct foo { int a, b, c, d;};voidprintfoo(const char *s, const struct foo *fp){ printf(s); printf(" structure at 0x%x\n", (unsigned)fp); printf(" foo.a = %d\n", fp->a); printf(" foo.b = %d\n", fp->b); printf(" foo.c = %d\n", fp->c); printf(" foo.d = %d\n", fp->d);}void *thr_fn1(void *arg){ struct foo foo = {1, 2, 3, 4}; printfoo("thread 1:\n", &foo); pthread_exit((void *)&foo);}void *thr_fn2(void *arg){ printf("thread 2: ID is %ld\n", pthread_self()); pthread_exit((void *)0);}intmain(void){ struct foo foo = {1, 2, 3, 4}; printfoo("thread 1:\n", &foo); pthread_exit((void *)&foo);}void *thr_fn2(void *arg){ printf("thread 2: ID is %ld\n", pthread_self()); pthread_exit((void *)0);}intmain(void){ int err; pthread_t tid1, tid2; struct foo *fp; err = pthread_create(&tid1, NULL, thr_fn1, NULL); if (err != 0) err_quit("can't create thread 1: %s\n", strerror(err)); err = pthread_join(tid1, (void *)&fp); if (err != 0) err_quit("can't join with thread 1: %s\n", strerror(err)); sleep(1); printf("parent starting second thread\n"); err = pthread_create(&tid2, NULL, thr_fn2, NULL); if (err != 0) err_quit("can't create thread 2: %s\n", strerror(err)); sleep(1); printfoo("parent:\n", fp); exit(0);}
0 0
- 编译Unix高级编程源代码出现的格式warning
- 《UNIX环境高级编程》apue源代码Ubuntu下的编译
- 《UNIX环境高级编程》apue源代码Ubuntu下的编译
- 《UNIX环境高级编程》apue源代码Ubuntu下的编译
- 《unix环境高级编程》书中源代码编译问题解决
- 《unix环境高级编程》书中源代码编译问题解决
- 《unix环境高级编程》书中源代码编译问题解决
- 《unix环境高级编程》书中源代码编译 详细流程
- unix环境高级编程第三版源代码编译及使用
- unix环境高级编程第三版源代码编译及使用
- 《unix环境高级编程》源代码编译找不到apue.h等错误的解决办法
- 《unix环境高级编程》源代码编译找不到apue.h等错误的解决办法
- APUE(UNIX环境高级编程)的源代码编译与调试
- 《unix环境高级编程》源代码编译找不到apue.h等错误的解决办法
- 《unix环境高级编程》源代码编译找不到apue.h等错误的解决办法
- UNIX环境高级编程 源代码编译apue.h头文件的问题
- UNIX环境高级编程的编译问题
- 编译UNIX网络编程源代码
- CentOS设置网络访问代理
- jquery的ajax提交时“加载中”提示的处理方法
- LearnOpenGL学习笔记4:纹理
- vpn tomcat
- echarts相关配置及图示
- 编译Unix高级编程源代码出现的格式warning
- iOS中有关沙盒的一些知识的介绍(获取沙盒路径以及沙盒文件操作等)
- apache tomcat 默认访问项目(直接输入IP就能访问项目)
- racle instr函数(oracle 用instr 来代替 like)
- json字符串返回给前端处理
- java三大版本
- Window下硬盘安装Ubuntu系统
- apache/nginx/nodejs原理简析
- easyui Tree事件执行顺序