C有时想找预定义类型


    今天写线程,想看看 pthread_t 的实际类型是什么,vi /usr/include/pthread.h 头文件,最后找到  pthread_t 定义在#include <bits/pthreadtypes.h> 该头文件中,一步一步的找可以找出来,不过麻烦;不如用 gcc -E cfile.c  -o cfile.e 预编译,然后grep pthread_t 就可以看到定义为:typedef unsigned long int pthread_t; 比较好用。

   当然需要对gcc的编译几个阶段熟悉,gcc -${E,S,c} .. 和记住这个单词,逃生(escape),就可以记住。


[root@localhost pthread]# cat pthreadtest.c  

#include <pthread.h>

#include <stdio.h>

#include <unistd.h>

#include <stdlib.h>



int * thread(void * thread)

{

    pthread_t newthid;

    

    newthid = pthread_self();

   

    printf("new thread id is : %u \n",newthid);

}

int main(int argc,char ** argv,char **envp)

{


    pthread_t thid;

    

   if(pthread_create(&thid,NULL,(void*)thread,NULL)!=0)

   {

        printf("Create failed.\n");

        exit(1);


   }

   sleep(1);

   exit(0);

}

编译记得席上  gcc cfile.c  -lpthread  -o pthreadtest.bin 

因为不在默认搜索路径上

[root@localhost pthread]# find / -name libpthread*

/usr/lib/libpthread_nonshared.a

/usr/lib/libpthread.so

/lib/libpthread.so.0

/lib/libpthread-2.12.so

/lib/i686/nosegneg/libpthread.so.0

/lib/i686/nosegneg/libpthread-2.12.so

----查看这个文件

[root@localhost pthread]# t=/usr/lib/libpthread.so   && file $t && echo -e "\n\n"&& cat $t

/usr/lib/libpthread.so: ASCII C program text




/* GNU ld script

   Use the shared library, but some functions are only in

   the static library, so try that secondarily.  */

OUTPUT_FORMAT(elf32-i386)

GROUP ( /lib/libpthread.so.0 /usr/lib/libpthread_nonshared.a )


转载于:https://my.oschina.net/u/177808/blog/298377

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值