(转载)关于void *指针的一点心得....
2013-05-01 20:26
295 查看
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <semaphore.h> #include <sys/types.h> #include <dirent.h> #include <pthread.h> #include <errno.h> #include <signal.h> #include <time.h> struct food { int a; int b; int c; }; struct food apple; void* task1(void* arg) { apple.a = 23; apple.b = 82; apple.c = 59; pthread_exit((void*)&apple); } int main(int argc, char *argv[]) { pthread_t thrd1, thrd2, thrd3; void* tret; pthread_create(&thrd1, NULL, (void*)task1, NULL); pthread_join(thrd1, (void*)&tret); printf("The food:%d %d %d\n", tret->a, tret->b, tret->c); // 这行出现了严重的错误 printf("Main thread exit...\n"); return 0; }
程序输出:
[root@robot ~]# gcc thread_exit.c -lpthread -o thread_exit thread_exit.c: In function 'main': thread_exit.c:37: warning: dereferencing 'void *' pointer thread_exit.c:37: error: request for member 'a' in something not a structure or union thread_exit.c:37: warning: dereferencing 'void *' pointer thread_exit.c:37: error: request for member 'b' in something not a structure or union thread_exit.c:37: warning: dereferencing 'void *' pointer thread_exit.c:37: error: request for member 'c' in something not a structure or union [root@robot ~]#
相关文章推荐
- (转载)关于Linux下串口通信的一点心得
- 关于指针数组和数组指针的一点心得!
- [转载]关于文件系统和磁盘驱动的一点学习心得
- 关于指针的一点心得
- 关于指针的一点心得——20150603
- [转载] 关于matlab GUI的一点心得
- 关于对数组及指针使用sizeof的一点心得
- 关于void编程规范、void*(指针)、(void*)类型转换的详解
- 关于WAS一点心得
- 关于从网络Url中下载文件自己的一点心得
- 关于自己的一点心得EXtjs
- 关于jquery插件的一点使用心得
- 关于.net的combobox的一点使用心得
- 关于Android 中 Bitmap 内存回收的一点心得
- 关于mysql日期格式化的一点心得
- 关于Linux下串口通信的一点心得
- C语言 关于#define 与const 一点心得
- 关于position标签的一点心得
- 关于vertical-align的一点心得
- 关于UILabel的一点使用心得