使用GCC / G ++输入typedef [英] Typedef with GCC/G++

查看:175
本文介绍了使用GCC / G ++输入typedef的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出以下示例代码


typedef

struct fubar *

fubar;


struct fubar

{

};


int main(无效)

{

返回0;

}


Windows上的GCC会编译得很好,但是G ++会抛出错误说明


3:错误:''typedef struct fubar * fubar''的类型冲突$

2:错误:之前声明为''struct fubar''

6:错误:''struct fubar'的冲突类型''

3:错误:之前的声明为''typedef struct fubar * fubar''


现在我知道我可以通过简单地将结构重命名为

其他东西来避免这个错误,但我更愿意理解为什么这被解释为

不同。

Given the following example code

typedef
struct fubar *
fubar;

struct fubar
{
};

int main(void)
{
return 0;
}

GCC on Windows will compile this fine, but G++ throws an error saying

3: error: conflicting types for ''typedef struct fubar*fubar''
2: error: previous declaration as ''struct fubar''
6: error: conflicting types for ''struct fubar''
3: error: previous declaration as ''typedef struct fubar*fubar''

Now I know I can avoid this error by simply renaming the struct to
something else, but I''d prefer to understand why this is interpreted
differently.

推荐答案

2004年11月18日星期四21:46:54 -0800,Jeff Mott写道:
On Thu, 18 Nov 2004 21:46:54 -0800, Jeff Mott wrote:
考虑到这一点由于示例代码

typedef
struct fubar *
fubar;

struct fubar

}

int main(void)
{
返回0;
}

Windows上的GCC会编译得很好,但G ++会抛出错误说

3:错误:''typedef struct fubar * fubar''的冲突类型2:错误:上一个声明为''struct fubar''
6:错误:冲突的类型为''struct fubar''
3:错误:以前的声明为''typedef struct fubar * fubar''

现在我知道我可以通过简单地将结构重命名为其他的东西,但我更愿意理解为什么这个被解释不同。
Given the following example code

typedef
struct fubar *
fubar;

struct fubar
{
};

int main(void)
{
return 0;
}

GCC on Windows will compile this fine, but G++ throws an error saying

3: error: conflicting types for ''typedef struct fubar*fubar''
2: error: previous declaration as ''struct fubar''
6: error: conflicting types for ''struct fubar''
3: error: previous declaration as ''typedef struct fubar*fubar''

Now I know I can avoid this error by simply renaming the struct to
something else, but I''d prefer to understand why this is interpreted
differently.




好​​像你是故意问一个C ++问题C新闻组。


也许你应该尝试使用comp.lang.c ++而不是comp.lang.c.当然,首先要阅读他们的常见问题清单和/或章程(如果他们的b $ b有一个)可能是个好主意。

--Mac



Seems like you are knowingly asking a C++ question in a C newsgroup.

Maybe you should try comp.lang.c++ instead of comp.lang.c. It would
probably be a good idea to read their FAQ list and/or charter (if they
have one) first, of course.

--Mac




2004年11月18日星期五,Jeff Mott写道:

On Fri, 18 Nov 2004, Jeff Mott wrote:

给出以下示例代码
[snip] Windows上的GCC会编译得很好,但是G ++会抛出错误说

Given the following example code [snip] GCC on Windows will compile this fine, but G++ throws an error saying




不同的语言,不同的语法规则和不同的语义。

comp.lang.c ++在大厅里 - 问问那里,如果你真的想知道

为什么C ++会对待类名为类型,即使没有''struct''或''class''

标签附加。这个小组讨论了C,你的例子是完美的

有效C.


-Arthur



Different languages, different syntax rules and different semantics.
comp.lang.c++ is down the hall --- ask there, if you really want to know
why C++ treats class names as types even without the ''struct'' or ''class''
tag attached. This group discusses C, and your example is perfectly
valid C.

-Arthur


mj****@twcny.rr.com (Jeff Mott)写道:
mj****@twcny.rr.com (Jeff Mott) writes:
给定以下示例代码

typedef
struct fubar *
fubar;

struct fubar
{
};

int main(void)
{
返回0;
}

Windows上的GCC会编译得很好,但是G ++会抛出错误说

3:错误:''typedef struct fubar * fubar''的冲突类型2:错误:上一个声明为''struct fubar''
6:错误:冲突类型对于''struct fubar''
3:错误:以前的声明为''typedef struct fubar * fubar''

现在我知道我可以通过简单地将结构重命名为<来避免这个错误其他的东西,但我更愿意理解为什么这是inter不同的。
Given the following example code

typedef
struct fubar *
fubar;

struct fubar
{
};

int main(void)
{
return 0;
}

GCC on Windows will compile this fine, but G++ throws an error saying

3: error: conflicting types for ''typedef struct fubar*fubar''
2: error: previous declaration as ''struct fubar''
6: error: conflicting types for ''struct fubar''
3: error: previous declaration as ''typedef struct fubar*fubar''

Now I know I can avoid this error by simply renaming the struct to
something else, but I''d prefer to understand why this is interpreted
differently.




G ++是一个C ++编译器。尝试comp.lang.c ++(他们可能会告诉你/ b
,不像在C中,给出一个声明struct fubar {/ * ... * /},

类型可以简称为fubar。


-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

San迭戈超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。



G++ is a C++ compiler. Try comp.lang.c++ (where they''ll probably tell
you that, unlike in C, given a declaration "struct fubar { /* ... */}",
the type can be referred to as just "fubar").

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


这篇关于使用GCC / G ++输入typedef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆