pthread_t定义

老鼠爱上猫oc 2017-06-12 12:12:47
在头文件中看到
#typedef unsigned long int pthread_t
这句话怎么理解,pthread_t是一个什么类型呢?
...全文
2967 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
自信男孩 2017-06-12
  • 打赏
  • 举报
回复
typedef unsigned long int pthread_t少一个分号;因为typedef是一条完整的语句,而不是宏定义。
typedef unsigned long int pthread_t;
这句话的意思是,unsigned int别名是pthread_t,可以用pthread_t定义的变量,就相当与unsigned int定义的变量一样。
paschen 2017-06-12
  • 打赏
  • 举报
回复
相当于pthread_t实际是个unsigned long int,只不过用pthread_t表示线程ID
老鼠爱上猫oc 2017-06-12
  • 打赏
  • 举报
回复
引用 9楼paschen 的回复:
[quote=引用 4 楼 mark_qzh 的回复:] [quote=引用 1 楼 paschen 的回复:] 相当于pthread_t实际是个unsigned long int,只不过用pthread_t表示线程ID
那unsigned long int是个什么类型?无符号长整型?[/quote] 是的,就是long int的无符号型,现在的机器上占4字节[/quote]嗯,我被搞晕了,我在看apue,线程那章节写道实现的时候可用一个结构来代表pthread_t数据类型,所以可移植的操作系统实现不能把它作为整型处理,是不是不同的系统定义不一样?
真相重于对错 2017-06-12
  • 打赏
  • 举报
回复
以前有的机器int 占2个字节,因此要表示 4个字节的int 用long int 类似于64位下的 long long
paschen 2017-06-12
  • 打赏
  • 举报
回复
引用 4 楼 mark_qzh 的回复:
[quote=引用 1 楼 paschen 的回复:] 相当于pthread_t实际是个unsigned long int,只不过用pthread_t表示线程ID
那unsigned long int是个什么类型?无符号长整型?[/quote] 是的,就是long int的无符号型,现在的机器上占4字节
真相重于对错 2017-06-12
  • 打赏
  • 举报
回复
sizeof(long int),应该清楚了
赵4老师 2017-06-12
  • 打赏
  • 举报
回复
//char (*(*x[3])())[5];//x是什么类型的变量?
//
//分析C语言声明,关键是搞清楚这个变量是个什么东西(函数、指针、数组),
//是函数那么剩下的就是他的参数和返回值,
//是指针那剩下部分是说明他指向什么,
//是数组剩下的部分就是说明数组的成员是什么类型。
//解析C语言声明规则:
//从左侧第一个标识符开始,按照优先级进行结合。*表示是..的指针,const表示只读的,volatile表示可变的,[]表示是数组,()表示是函数。
//
//x和[3]结合说明是一个大小为3的数组,该数组的每个元素为一类指针,该类指针指向一类函数,该类函数无参数,返回一类指针,该类指针指向一个大小为5的char型数组
#include <stdio.h>
#include <typeinfo.h>
char num[5];
char (*x00())[5] {
    return #
}
int main() {
    char (*(*x[3])())[5];//是个数组,大小为3
    char (*(*x0  )())[5];//数组的元素,是个函数指针
    char (*( x00 )())[5];//函数原型,参数为空,返回值为指针
    char (*  x000   )[5];//返回值

    x0 = x00;
    x[0] = x0;
    x[1] = x0;
    x[2] = x0;
    printf("typeid(x).name() is %s\n",typeid(x).name());
    return 0;
}
//typeid(x).name() is char (* (__cdecl**)(void))[5]
赵4老师 2017-06-12
  • 打赏
  • 举报
回复
typedef typedef type-declaration synonym; The typedef keyword defines a synonym for the specified type-declaration. The identifier in the type-declaration becomes another name for the type, instead of naming an instance of the type. You cannot use the typedef specifier inside a function definition. A typedef declaration introduces a name that, within its scope, becomes a synonym for the type given by the decl-specifiers portion of the declaration. In contrast to the class, struct, union, and enum declarations, typedef declarations do not introduce new types — they introduce new names for existing types. Example // Example of the typedef keyword typedef unsigned long ulong; ulong ul; // Equivalent to "unsigned long ul;" typedef struct mystructtag { int i; float f; char c; } mystruct; mystruct ms; // Equivalent to "struct mystructtag ms;" typedef int (*funcptr)(); // funcptr is synonym for "pointer // to function returning int" funcptr table[10]; // Equivalent to "int (*table[10])();"
destory27 2017-06-12
  • 打赏
  • 举报
回复
unsigned long int == unsigned long 0-(2^64)-1
老鼠爱上猫oc 2017-06-12
  • 打赏
  • 举报
回复
引用 1 楼 paschen 的回复:
相当于pthread_t实际是个unsigned long int,只不过用pthread_t表示线程ID
那unsigned long int是个什么类型?无符号长整型?
老鼠爱上猫oc 2017-06-12
  • 打赏
  • 举报
回复
引用 2 楼 weixin_31656265 的回复:
typedef 前面有#?
没有的,白纸上写就不淡定了 哈哈
Aries Sun 2017-06-12
  • 打赏
  • 举报
回复
typedef 前面有#?

69,377

社区成员

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

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