谁能为我解释代码? [英] Could anyone explain the code for me?

查看:38
本文介绍了谁能为我解释代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码用于列表操作。但是我无法理解。

有人可以为我解释代码吗?


/ *

*列表定义。

* /


#define LIST_HEAD(名称,类型)

struct name {

type * lh_first ; / *第一个元素* /

}

#define LIST_ENTRY(类型)

struct {

type * le_next ; / *下一个元素* /

类型** le_prev; / *上一个下一个元素的地址* /

}


问题:

为什么结构没有名字?

列表是否为双向列表?


/ *

*列表功能。

* /

#define LIST_INIT(头){

(头) - > lh_first = NULL;

}


#define LIST_INSERT_AFTER(listelm,elm,field){

if(((elm) - > field.le_next =(listelm) - > field.le_next)!= NULL)

(listelm) - > field.le_next-> field.le_prev =

&(elm) - > field.le_next;

(listelm) - > field.le_next =(elm);

(elm) - > field.le_prev =&(listelm) - > field.le_next;

}


问题:

什么是listelm,elm,field?


#定义LIST_INSERT_HEAD(head,elm,field){

if(((elm) - > field.le_next =(head) - > lh_first)!= NULL)

(头) - > lh_first-> field.le_prev =

&(elm) - > field.le_next;

(头) - > lh_first =(elm);

(elm) - > field.le_prev =&(head) - > lh_first;

}


问题:


如果榆树成为头,最后一句话的目的是什么:

(elm) - > field.le_prev =&(head) - > lh_first;

提前致谢。


Jack

The following code is for list operation. But I can not understand.
Could anyone explain the code for me?

/*
* List definitions.
*/

#define LIST_HEAD(name, type)
struct name {
type *lh_first; /* first element */
}
#define LIST_ENTRY(type)
struct {
type *le_next; /* next element */
type **le_prev; /* address of previous next element */
}

Questions:
Why the struct does not have a name?
Is the list a two-way list?

/*
* List functions.
*/
#define LIST_INIT(head) {
(head)->lh_first = NULL;
}

#define LIST_INSERT_AFTER(listelm, elm, field) {
if (((elm)->field.le_next = (listelm)->field.le_next) != NULL)
(listelm)->field.le_next->field.le_prev =
&(elm)->field.le_next;
(listelm)->field.le_next = (elm);
(elm)->field.le_prev = &(listelm)->field.le_next;
}

Question:
What is listelm, elm, field?

#define LIST_INSERT_HEAD(head, elm, field) {
if (((elm)->field.le_next = (head)->lh_first) != NULL)
(head)->lh_first->field.le_prev =
&(elm)->field.le_next;
(head)->lh_first = (elm);
(elm)->field.le_prev = &(head)->lh_first;
}

Question:

If elm becomes head, what''s the purpose of the last sentence:
(elm)->field.le_prev = &(head)->lh_first;
Thanks in advance.

Jack

推荐答案

C ++ fan写道:
C++fan wrote:
以下代码用于列表操作。但是我无法理解。
有人可以为我解释代码吗?

/ *
*列表定义。
* /

#define LIST_HEAD(name,type)
这没什么用处。

struct name {
type * lh_first; / *第一个元素* /
}


结构定义后缺少分号。

#define LIST_ENTRY(类型)
见以上。

struct {
type * le_next; / *下一个元素* /
类型** le_prev; / *上一个下一个元素的地址* /
我怀疑le_prev'的评论是错误的。当然le_prev是列表中先前的

节点,而不是之前的le_next(这是/ this / node)。

}

问题:
为什么struct没有名字?


对我来说看起来像是个错误。

这个列表是双向列表吗?
那么有指向前一个节点和下一个节点的指针...

/ *
*列表功能。
* /
#define LIST_INIT(头部) ){
(head) - > lh_first = NULL;
}


这不是宏的工作方式。阅读教科书。

#define LIST_INSERT_AFTER(listelm,elm,field){
if(((elm) - > field.le_next =(listelm) - > field.le_next) != NULL)
(listelm) - > field.le_next-> field.le_prev =
&(elm) - > field.le_next;
(listelm) - > field.le_next =(elm);
(elm) - > field.le_prev =&(listelm) - > field.le_next;
}

问题:<什么是聆听,榆树,田地?
它们是函数式宏的参数。写这篇文章的人不会理解宏,而应该使用函数。

#define LIST_INSERT_HEAD(head,elm,field){
if(((elm) - > field.le_next =(head) - > lh_first)!= NULL)
(head) - > lh_first-> field.le_prev =
& ;(elm) - > field.le_next;
(head) - > lh_first =(elm);
(elm) - > field.le_prev =&(head) - > lh_first ;
}

问:
如果榆树成为头,最后一句的目的是什么:
(榆木) - > field.le_prev =&(head) - > lh_first;
The following code is for list operation. But I can not understand.
Could anyone explain the code for me?

/*
* List definitions.
*/

#define LIST_HEAD(name, type) This doesn''t do anything useful.
struct name {
type *lh_first; /* first element */
}
Missing semi-colon after struct definition.
#define LIST_ENTRY(type) See above.
struct {
type *le_next; /* next element */
type **le_prev; /* address of previous next element */ I suspect le_prev''s comment is wrong. Surely le_prev is the previous
node in the list, not the previous le_next (which is /this/ node).
}

Questions:
Why the struct does not have a name?
Looks like an error to me.
Is the list a two-way list? Well there are pointers to both previous and next nodes...

/*
* List functions.
*/
#define LIST_INIT(head) {
(head)->lh_first = NULL;
}
That isn''t how macros work. Read a textbook.

#define LIST_INSERT_AFTER(listelm, elm, field) {
if (((elm)->field.le_next = (listelm)->field.le_next) != NULL)
(listelm)->field.le_next->field.le_prev =
&(elm)->field.le_next;
(listelm)->field.le_next = (elm);
(elm)->field.le_prev = &(listelm)->field.le_next;
}

Question:
What is listelm, elm, field? They''re arguments to a function-style macro. Whoever wrote this doesn''t
understand macros, and should be using functions instead.


#define LIST_INSERT_HEAD(head, elm, field) {
if (((elm)->field.le_next = (head)->lh_first) != NULL)
(head)->lh_first->field.le_prev =
&(elm)->field.le_next;
(head)->lh_first = (elm);
(elm)->field.le_prev = &(head)->lh_first;
}

Question:

If elm becomes head, what''s the purpose of the last sentence:
(elm)->field.le_prev = &(head)->lh_first;




如何使用函数,以便我们可以看到参数的类型

是?如果可能的话,发一个可编译的例子。


HTH,

雅克。



How about using functions so we can see what the types of the arguments
are? If possible, post a compileable example.

HTH,
Jacques.


C ++粉丝skrev i meldingen

< 15 ************************** @ posting.google。 COM取代。 ..
C++fan skrev i meldingen
<15**************************@posting.google.com>. ..
以下代码用于列表操作。但是我无法理解。
任何人都可以为我解释一下代码吗?
The following code is for list operation. But I can not understand.
Could anyone explain the code for me?




这是对C ++代码的一次尝试/>
基本编程。它甚至在语法上都不正确。搜索

代表含义在这样的代码是没用的;仅评估语法。



It''s an attempt at C++ code written by someone probably learning
basic programming. It''s not even syntactically correct. Searching
for "meaning" in such code is useless; evaluate on syntax only.


" C ++粉丝" < JW **** @ excite.com>在消息中写道

news:15 ************************** @ posting.google.c om ...
"C++fan" <jw****@excite.com> wrote in message
news:15**************************@posting.google.c om...
以下代码用于列表操作。但是我无法理解。
有人可以为我解释代码吗?

/ *
*列表定义。
* /

#define LIST_HEAD(名称,类型)
结构名称{
类型* lh_first; / *第一个元素* /
}
#define LIST_ENTRY(类型)
struct {
type * le_next; / *下一个元素* /
类型** le_prev; / *上一个下一个元素的地址* /
}

问题:
为什么结构没有名称?
列表是否为双向列表?

/ *
*列表功能。
* /
#define LIST_INIT(头){
(头) - > lh_first = NULL;
}

#define LIST_INSERT_AFTER(listelm,elm,field){
if(((elm) - > field.le_next =(listelm) - > field.le_next) != NULL)
(listelm) - > field.le_next-> field.le_prev =
&(elm) - > field.le_next;
(listelm) - > field.le_next =(elm);
(elm) - > field.le_prev =&(listelm) - > field.le_next;
}

问题:<什么是listelm,elm,field?

#define LIST_INSERT_HEAD(head,elm,field){
if(((elm) - > field.le_next =(head) - > lh_first)!= NULL)
(head) - > lh_first-> field.le_prev =
&(elm) - > field.le_next;
(head) - > lh_fir st =(elm);
(elm) - > field.le_prev =&(head) - > lh_first;
}

问题:
<如果榆树成为头,那么最后一句话的目的是什么:
(榆树) - > field.le_prev =&(head) - > lh_first;

提前致谢。

杰克
The following code is for list operation. But I can not understand.
Could anyone explain the code for me?

/*
* List definitions.
*/

#define LIST_HEAD(name, type)
struct name {
type *lh_first; /* first element */
}
#define LIST_ENTRY(type)
struct {
type *le_next; /* next element */
type **le_prev; /* address of previous next element */
}

Questions:
Why the struct does not have a name?
Is the list a two-way list?

/*
* List functions.
*/
#define LIST_INIT(head) {
(head)->lh_first = NULL;
}

#define LIST_INSERT_AFTER(listelm, elm, field) {
if (((elm)->field.le_next = (listelm)->field.le_next) != NULL)
(listelm)->field.le_next->field.le_prev =
&(elm)->field.le_next;
(listelm)->field.le_next = (elm);
(elm)->field.le_prev = &(listelm)->field.le_next;
}

Question:
What is listelm, elm, field?

#define LIST_INSERT_HEAD(head, elm, field) {
if (((elm)->field.le_next = (head)->lh_first) != NULL)
(head)->lh_first->field.le_prev =
&(elm)->field.le_next;
(head)->lh_first = (elm);
(elm)->field.le_prev = &(head)->lh_first;
}

Question:

If elm becomes head, what''s the purpose of the last sentence:
(elm)->field.le_prev = &(head)->lh_first;
Thanks in advance.

Jack




杰克,这真是一个难题。作为一个真正的C ++粉丝我希望你实际上不会使用这样的垃圾,除非你必须这样做! (提示:标准::列表)


无论如何,我对这一点很不确定但可能使用如下:


struct fred_node

{

LIST_ENTRY(struct fred_node)节点;

Fred fred; // Fred是一些任意类型 - 这是Freds的列表

};


转换为:


struct fred_node

{

struct {

struct fred_node * le_next; / * next element * /

struct fred_node ** le_prev; / *上一个下一个元素的地址* /

}节点;

Fred fred; // Fred是一些任意类型 - 这是Freds的列表

};


这定义了节点类型。然后列出清单:


LIST_HEAD(fred_head,struct fred_node)fredlist;

LIST_INIT(fredlist);


相当于:


struct fred_head {

struct fred_node * lh_first; / *第一个元素* /

} fredlist;

fredlist-> lh_first = NULL;


现在添加一个节点:


struct fred_node * new_node =(struct fred_node *)malloc(sizeof(struct

fred_node));

new_node.fred =弗雷德(21); //无论是什么意思

LIST_INSERT_HEAD(mylist,new_node,node);


扩展为


struct fred_node * new_node =(struct fred_node *)malloc(sizeof(struct

fred_node));

new_node.fred = Fred(21); //无论是什么意思

if((new_node-> node.le_next =(fredlist) - > lh_first)!= NULL)

fredlist-> lh_first- > node.le_prev =& new_node-> node.le_next;

fredlist-> lh_first = new_node;

new_node-> node.le_prev =& new_node;


现在添加另一个节点:

struct fred_node * newer_node =(struct fred_node *)malloc(sizeof(struct

fred_node));

newer_node.fred = Fred(-33); //无论是什么意思

LIST_INSERT_AFTER(newer_node,new_node,node);


扩展为:


struct fred_node * newer_node =(struct fred_node *)malloc(sizeof(struct

fred_node));

newer_node.fred = Fred(-33); //无论是什么意思

if((new_node-> node.le_next = newer_node-> node.le_next)!= NULL)

newer_node-> node。 le_next-> node.le_prev =& new_node-> node.le_next;

newer_node-> node.le_next = new_node;

new_node-> node。 le_prev =& new_node;


嗯,这就是我想出来的。我没有测试任何东西。祝你好运。


-

Cy
http://home.rochester.rr.com/cyhome/


这篇关于谁能为我解释代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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