比较两个结构 [英] comparing two structures
问题描述
伙计们,
使用
" memcmp"这是比较两个结构是否相等的好方法。 ?
如果没有,可能与此相关的问题是什么?什么是
正确的
方法呢?
感谢您的帮助。
>
推荐答案
ju ***** *****@yahoo.co.in 说:
伙计们,
这是一个通过使用
" memcmp"来比较两个结构的平等性的好方法?
Guys,
Is it a good way to compare two structures for equality by using
"memcmp" ?
No.
No.
如果没有,可能与此相关的问题是什么?
If not, what could be the problems associated with this ?
填充字节,以及struct
成员指向的动态分配内存。
Padding bytes, and dynamically allocated memory pointed to by struct
members.
这样做的正确方法是什么?
And what is the correct method of doing this ?
int cmp(const struct T * a,const struct T * b);
-
Richard Heathfield< http://www.cpax.org.uk>
电邮:-www。 + rjh @
谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>
Usenet是一个奇怪的放置" - dmr 1999年7月29日
int cmp(const struct T *a, const struct T *b);
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
< ju ********** @ yahoo.co.inschrieb im Newsbeitrag
news :11 ********************* @ w3g2000hsg.googlegrou ps.com ...
<ju**********@yahoo.co.inschrieb im Newsbeitrag
news:11*********************@w3g2000hsg.googlegrou ps.com...
伙计们,
使用
" memcmp"这是比较两个结构是否相等的好方法。 ?
如果没有,可能与此相关的问题是什么?什么是
正确的
方法呢?
感谢您的帮助。
Guys,
Is it a good way to compare two structures for equality by using
"memcmp" ?
If not, what could be the problems associated with this ? And what is
the correct
method of doing this ?
thanks for any help.
http://c-faq.com/ struct / compare.html
Richard Heathfield写道:
Richard Heathfield wrote:
ju ********** @ yahoo.co.in 说:
>通过使用
memcmp来比较两个结构的平等性是一种好方法吗? ?
>Is it a good way to compare two structures for equality by using
"memcmp" ?
No.
No.
>如果没有,可能与此相关的问题是什么?
>If not, what could be the problems associated with this ?
填充字节,以及
结构成员指向的动态分配内存。
Padding bytes, and dynamically allocated memory pointed to by
struct members.
>这样做的正确方法是什么?
>And what is the correct method of doing this ?
int cmp(const struct T * a,const struct T * b);
int cmp(const struct T *a, const struct T *b);
哪个应解决(非常粗略):
for(c =每个组件的a){
if((a-> c)!=(b-> c))return 0; / * unequal * /
}
返回1; / * ie结构相等* /
这意味着你必须编写一个cmp()每种结构类型。你可能需要
来解析嵌入式指针。 br />
-
Chuck F(cinefalconer at maineline dot net)
可用于咨询/临时嵌入式和系统。
< http://cbfalconer.home.att.net>
-
通过 http://www.teranews.com
Which should resolve to (very roughly}:
for (c = eachcomponentof a) {
if ((a->c) != (b->c)) return 0; /* unequal */
}
return 1; /* i.e. structures equal */
Which means you have to write a cmp() each structure type. You may
have to resolve embedded pointers.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com
这篇关于比较两个结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!