伙计们, 使用 " 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< www.cpax.uk> 电邮:-www。 + rjh @ 谷歌用户:< www.cpax.uk/prg/writings/googly.php> Usenet是一个奇怪的放置" - dmr 1999年7月29日
int cmp(const struct T *a, const struct T *b); -- Richard Heathfield <www.cpax.uk> Email: -www. +rjh@ Google users: <www.cpax.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 ... <ju**********@yahoo.co.inschrieb im Newsbeitrag news:11*********************@w3g2000hsg.googlegrou ps... 伙计们, 使用 " 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.
c-faq/ 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) 可用于咨询/临时嵌入式和系统。 < cbfalconer.home.att> - 通过 www.teranews
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. <cbfalconer.home.att> -- Posted via a free Usenet account from www.teranews
更多推荐
比较两个结构
发布评论