typedef重定义错误

记录一个问题。


Item.h文件:

typedef int Item;


Link.h文件:

#include "Item.h"

void LINKinit(int);


Link.c文件:

#include "stdio.h"

#include "Link.h"

#inlcude "Item.h"


void LINKint(int n)

{

    printf("Create a new LINK.\n");

}


进行编译:gcc -o link.o -c Link.c出现如下错误:

In file included from Link.h:1,
                 from Link.c:2:
Item.h:1: 错误:typedef‘Item’重定义
Item.h:1: 附注:‘Item’的上一个声明在此


修改Item.h:

 #ifndef __ITEM__
 #define __ITEM__
 typedef int Item;
 #endif
这样就可以解决typedef重定义的问题。


这个在linux 2.6.32-220.el6.x86_64上运行 gcc4.4.6时出现。但是在F17(3.3.4-5.fc17.i686)上运行gcc4.7.2时没出现这个问题。

在网上找到一篇比较靠谱的解释,http://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=ce3765bf44e49ef0568a1ad4a0b7f807591d6412

authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> 
 Sun, 23 May 2010 20:47:16 +0000 (20:47 +0000)
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> 
 Sun, 23 May 2010 20:47:16 +0000 (20:47 +0000)
typedefs with different but compatible types.  Allow duplicate
typedefs with the same type except for pedantic non-C1X, but give
warning for variably modified types.

如果在编译时,加上-pedantic,则会有warning信息。


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值