我用printf %ld输出线程ID为什么输出的是负数??线程类型是pthread_t格式

a309261868 2013-05-21 05:19:48
RT
我用printf %ld输出线程ID为什么输出的是负数??线程类型是pthread_t格式
...全文
813 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
绯红女王 2013-05-22
  • 打赏
  • 举报
回复
ID的最高位是1啊! 你用ld格式输出肯定是负数啦~ LZ试试用lu格式输出
AnYidan 2013-05-21
  • 打赏
  • 举报
回复
Recall that a process ID, represented by the pid_t data type, is a non-negative integer. A thread ID is represented by the pthread_t data type. Implementations are allowed to use a structure to represent the pthread_t data type, so portable implementations can't treat them as integers.
图灵狗 2013-05-21
  • 打赏
  • 举报
回复
只要ID的最高位为1,那么用%ld输出就会是负数,你想打印正的就用%lu格式。

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧