expected ';' identifier or '(' before 'struct'

dragonmuou 2012-09-12 03:12:15

#ifndef _IPV4_H
#define _IPV4_H

struct ipv4_h {
#if __BYTE_ORDER == __LITTLE_ENDIAN
unsigned int hlen :4;
unsigned int ver :4;
#elif __BYTE_ORDER == __BIG_ENDIAN
unsigned int ver :4;
unsigned int hlen :4;
#else
#error "please fix <bits/endian.h>"
#endif
uint8_t tos;
uint16_t tot_len;
uint16_t id;
#if __BYTE_ORDER == __LITTLE_ENDIAN
uint16_t frag_off1 :5;
uint16_t mf :1;
uint16_t df :1;
uint16_t res :1;
uint16_t frag_off2 :8;
#define IP_SET_FRAGOFF(ip,v) {(ip)->frag_off1=((v)&0x1f00)>>8; (ip)->frag_off2=(v)&0x00ff;}
#elif __BYTE_ORDER == __BIG_ENDIAN
uint16_t res :1;
uint16_t df :1;
uint16_t mf :1;
uint16_t frag_off :13;
#define IP_SET_FRAGOFF(ip,v) (ip)->frag_off=(v)
#else
#error "please fix <bits/endian.h>"
#endif
uint8_t ttl;
uint8_t protocol;
uint16_t checksum;
uint32_t saddr;
uint32_t daddr;
};
#endif

...全文
601 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2012-09-12
  • 打赏
  • 举报
回复
偶遇到类似问题都是用
“每次用/*...*/注释掉不同部分再重新编译,直到定位到具体语法出错的位置。”
的方法解决的。
dragonmuou 2012-09-12
  • 打赏
  • 举报
回复
多谢多谢 问题解决了,是在其他.h文件中,结构体定义错误,不过这个错误定位也太忽悠了,怎么会定位到这个文件来,这个文件我根本没有引用到其他文件,多谢啊[Quote=引用 3 楼 的回复:]
引用 2 楼 的回复:
囧,那为什么我的gcc编译不通过,肯跌啊

引用 1 楼 的回复:
C/C++ code


typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;

#ifndef _IPV4_H
#define _IPV4_H
……
[/Quote]
Corner 2012-09-12
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
囧,那为什么我的gcc编译不通过,肯跌啊

引用 1 楼 的回复:
C/C++ code


typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;

#ifndef _IPV4_H
#define _IPV4_H

struct ipv4……
[/Quote]
额,我增加了uint8_t、uint16_t、uint32_t的定义。你的宏扩展开之后得到的结构体定义是什么。。
dragonmuou 2012-09-12
  • 打赏
  • 举报
回复
囧,那为什么我的gcc编译不通过,肯跌啊[Quote=引用 1 楼 的回复:]
C/C++ code


typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;

#ifndef _IPV4_H
#define _IPV4_H

struct ipv4_h {
#if __BYTE_ORDER == __LITTLE_EN……
[/Quote]
Corner 2012-09-12
  • 打赏
  • 举报
回复

typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;

#ifndef _IPV4_H
#define _IPV4_H

struct ipv4_h {
#if __BYTE_ORDER == __LITTLE_ENDIAN
unsigned int hlen :4;
unsigned int ver :4;
#elif __BYTE_ORDER == __BIG_ENDIAN
unsigned int ver :4;
unsigned int hlen :4;
#else
#error "please fix <bits/endian.h>"
#endif
uint8_t tos;
uint16_t tot_len;
uint16_t id;
#if __BYTE_ORDER == __LITTLE_ENDIAN
uint16_t frag_off1 :5;
uint16_t mf :1;
uint16_t df :1;
uint16_t res :1;
uint16_t frag_off2 :8;
#define IP_SET_FRAGOFF(ip,v) {(ip)->frag_off1=((v)&0x1f00)>>8; (ip)->frag_off2=(v)&0x00ff;}
#elif __BYTE_ORDER == __BIG_ENDIAN
uint16_t res :1;
uint16_t df :1;
uint16_t mf :1;
uint16_t frag_off :13;
#define IP_SET_FRAGOFF(ip,v) (ip)->frag_off=(v)
#else
#error "please fix <bits/endian.h>"
#endif
uint8_t ttl;
uint8_t protocol;
uint16_t checksum;
uint32_t saddr;
uint32_t daddr;
};
#endif

试了下编译通过的

69,373

社区成员

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

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