typedef,structs和pointers [英] typedef, structs, and pointers

查看:90
本文介绍了typedef,structs和pointers的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释为什么以下情况不可能吗?

typedef foobar {

int x;

foobar * next; / *为什么我们不能这样做? * /

};

谢谢

Can someone please explain why the following is not possible?
typedef foobar {
int x;
foobar *next; /* why can''t we do this? */
};
Thanks

推荐答案

Steve Carter< st *** @ 127.0.0.1wrote:
Steve Carter <st***@127.0.0.1wrote:

>有人可以解释为什么以下是不可能的吗?

typedef foobar {

int x;

foobar * next; / *为什么我们不能这样做? * /
};

谢谢
>Can someone please explain why the following is not possible?
typedef foobar {
int x;
foobar *next; /* why can''t we do this? */
};
Thanks



缺少''struct'' - 缺少typedef的新名称。


你可能想要这样的东西:


typedef struct foobar {

int x;

struct foobar * next;

} FooBar;


然后你可以使用

FooBar fb声明新的结构;


fb.next = ...;等等

Missing ''struct'' - Missing new name for typedef.

You probably want something like this:

typedef struct foobar {
int x;
struct foobar *next;
} FooBar;

Then you can declare new structures using

FooBar fb;

fb.next = ...; etc.


Roberto Waltman写道:
Roberto Waltman wrote:

缺少''struct'' - 缺少新的typedef的名称。
Missing ''struct'' - Missing new name for typedef.



哎呀,我忘了把''struct''放进去(虽然,我的意思是)。我仍然不知道为什么你不能使用typedef名称作为''next''指针,

虽然。

typedef struct foobar {

int x;

foobar * next;

};


Oops, I forgot to put ''struct'' in (though, I meant to). I still don''t
understand why you can''t use the typedef name for ''next'' pointer,
though.
typedef struct foobar {
int x;
foobar *next;
};


在文章< e9 ********** @ nntp.aioe.org> ;,, Steve Carter< st *** @ 127.0.0.1wrote:
In article <e9**********@nntp.aioe.org>, Steve Carter <st***@127.0.0.1wrote:

>有人可以解释为什么以下不可能吗?
>Can someone please explain why the following is not possible?


> typedef foobar {

int x;

foobar * next; / *为什么我们不能这样做? * /
};
>typedef foobar {
int x;
foobar *next; /* why can''t we do this? */
};



因为我这么说 ;-)


typedef的typename在声明结束后才被视为存在,并且设计C的人没有

碰巧在本案例的前向引用中设计。他们在struct case的前向引用中做了
设计。我无法想象

当任何技术原因会阻止实施

对于typedef的前向引用,但是 - 或许 - 它会使

解析器显然比较棘手。

-

编程是在你忙于制定其他计划的时候发生的事情。

"Because I say so" ;-)

The typename for the typedef is not considered to exist until
the end of the declaration, and the people who designed C did not
happen to design in forward references for this case. They did
design in forward references for the struct case. I cannot think at
the moment of any technical reason that would block implementing
forward references for typedef, but -perhaps- it would make the
parser noticably trickier.
--
Programming is what happens while you''re busy making other plans.


这篇关于typedef,structs和pointers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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