您的位置:首页 > 编程语言 > C语言/C++

C语言中typedef可以出现在struct定义之前

2011-07-22 14:45 405 查看
一直以为typedef必须在相应的数据类型之后才可定义,原来在前面也可以:

#include <stdio.h>
#include <stdlib.h>

/* the typedef is before the struct */
typedef struct pcap_if* pcap_if_p;

struct pcap_if {
struct pcap_if *next;
int a;
};

int main()
{
const pcap_if_p a = (pcap_if_p)malloc(sizeof(struct pcap_if));
a->a = 1;
a->a = 2;
printf("%d", a->a);

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: