关于用typedef定义结构体类型
来源:互联网 发布:linux open函数 编辑:程序博客网 时间:2024/04/27 16:16
很痛苦啊,刚把动态链接库搞定,今天调用DSOpenProject函数又出现了错误。用dlerror函数输出错误信息,说是”Function not implemented (DSOpenProject)“。晕,怎么可能没实现呢,库函数里不都有么。
扯远了。开始我以为是数据类型有错误,打开dsapi.h,找到了DSPROJECT类型的定义处:
typedef struct _DSPROJECT
{
int dsapiVersionNo; /* Version of DSAPI being used */
int sessionId; /* The InterCALL session id */
unsigned char valueMark; /* This sessions value mark character */
unsigned char fieldMark; /* This sessions field mark character */
} * DSPROJECT;
我C++小菜啊!按小菜的理解,_DSPROJECT是定义的结构体数据类型名,而DSPROJECT是一个指向_DSPROJECT类型的指针变量。可是,在头文件里定义变量干嘛呢???
百度了下,找到一篇讲用typedef定义结构体类型的文章,粘贴如下:
(原文:http://blog.csdn.net/eion/archive/2003/05/30/14548.aspx)
#define S(s) printf("%s/n", #s); s
typedef struct _TS1{
int x, y;
} TS1, *PTS1, ***PPPTS1; // TS1是结构体的名称,PTS1是结构体指针的名称
// 也就是将结构体struct _TS1 命名为TS1,
// 将struct _TS1 * 命名为 PTS1
// 将struct _TS1 *** 命名为 PPPTS1
typedef struct { // struct后面的结构体说明也可以去掉
int x, y;
} TS2, *PTS2;
typedef PTS1 *PPTS1; // 定义PPTS1是指向PTS1的指针
typedef struct _TTS1{
typedef struct ITTS1 {
int x, y;
} iner;
iner i;
int x, y;
} TTS1;
//结构体内部的结构体也一样可以定义
typedef TTS1::ITTS1 ITS1;
void test_struct()
{
// 基本结构体重定义的使用
TS1 ts1 = {100, 200};
PTS1 pts1 = &ts1; // 完全等价于TS1* pts1 = &ts1;
PPTS1 ppts1 = &pts1; // 完全等价于TS1** ppts1 = &pts1;
PPPTS1 pppts1 = &ppts1; // 完全等价于 TS1*** pppts1 = &ppts1;
TS2 ts2 = {99, 88};
PTS2 pts2 = &ts2; // 完全等价于 TS2* pts2 = &ts2;
TTS1 itts1 = {{110, 220}, 10, 20};
Its1* rits1 = &itts1.i;
ITS1* &its1 = rits1; // 等价于 TTS1::ITTS1 *its1 = &(itts1.i);
printf("ts1/t = (%d, %d)/n*pts1/t = (%d, %d)/n"
"**ppts1/t = (%d, %d)/n***pppts1= (%d, %d)/n/n",
ts1.x, ts1.y, pts1->x, pts1->y,
(**ppts1).x, (**ppts1).y, (***pppts1).x, (***pppts1).y);
printf("ts2/t = (%d, %d)/n*pts2/t = (%d, %d)/n/n",
ts2.x, ts2.y, pts2->x, pts2->y);
printf("itts1/t = [(%d, %d), %d, %d]/n*its1/t = (%d, %d)/n/n",
itts1.i.x, itts1.i.y, itts1.x, itts1.y, its1->x, its1->y);
S(pts1->x = 119);
S(pts2->y = 911);
S(its1->x = 999);
printf("ts1/t = (%d, %d)/n*pts1/t = (%d, %d)/n"
"**ppts1/t = (%d, %d)/n***pppts1= (%d, %d)/n/n",
ts1.x, ts1.y, pts1->x, pts1->y,
(**ppts1).x, (**ppts1).y, (***pppts1).x, (***pppts1).y);
printf("ts2/t = (%d, %d)/n*pts2/t = (%d, %d)/n/n",
ts2.x, ts2.y, pts2->x, pts2->y);
printf("itts1/t = [(%d, %d), %d, %d]/n*its1/t = (%d, %d)/n/n",
itts1.i.x, itts1.i.y, itts1.x, itts1.y, its1->x, its1->y);
S((*ppts1)->y = -9999);
printf("ts1/t = (%d, %d)/n**ppts1/t = (%d, %d)/n/n",
ts1.x, ts1.y, (*ppts1)->x, (*ppts1)->y);
S((**pppts1)->x = -12345);
S((***pppts1).y = -67890);
printf("ts1/t = (%d, %d)/n*pts1/t = (%d, %d)/n"
"**ppts1/t = (%d, %d)/n***pppts1= (%d, %d)/n/n",
ts1.x, ts1.y, pts1->x, pts1->y,
(**ppts1).x, (**ppts1).y, (***pppts1).x, (***pppts1).y);
}
按上文所讲,DSPROJECT也是数据类型名,它是一个指向_DSPROJECT数据体类型的指针类型。这样就make sense了。
typedef struct _DSPROJECT
{
int dsapiVersionNo; /* Version of DSAPI being used */
int sessionId; /* The InterCALL session id */
unsigned char valueMark; /* This sessions value mark character */
unsigned char fieldMark; /* This sessions field mark character */
} * DSPROJECT;
这么基础的东西我都还不知道,晓习路漫漫啊。。。
- 关于用typedef定义结构体类型
- 用typedef定义结构体
- typedef 结构体定义
- typedef 定义结构体
- 用typedef定义类型
- 用typedef定义类型
- 结构体定义 typedef struct
- 用typedef定义类型总结。
- 用typedef定义函数类型
- C++ 用typedef定义类型
- C语言基础之结构体、共用体、枚举、类型定义typedef
- 结构标签(struct tag)与类型定义(typedef)的区别
- 结构体定义 typedef struct 用法详解
- 结构体定义 typedef struct 用法详解
- 结构体定义 typedef struct 学习
- 数据结构(结构体定义,typedef)
- typedef struct与struct定义结构体
- 结构体定义 typedef struct 用法详解
- 了解使用 ASP.NET AJAX 进行局部页面更新——ASP.NET AJAX学习笔记“出自msdn”
- shell判断表达式
- POJ 1068
- C#中textbox只能输入数字
- Android中包含多个Activity的应用退出按钮实现
- 关于用typedef定义结构体类型
- 临床路径实施难点探讨
- ping不通 虚拟机
- HBITMAP 保存为JPG格式
- 广州公安局综合办证厅地址
- sudo的环境变量获取
- Enterprise Linux5 配置Samba服务器
- 广州出生婴儿登记入户程序
- RGB图像数据字符叠加,图像压缩(ijl库),YUV转RGB